我有大約100個需要導入到listview的本地英雄圖像。這是我的hero.jsReact Native:如何用動態名稱導入本地圖像
renderRow(hero) {
return (
<View>
<View style={styles.container}>
<Image
source={require('./img/hero/'+hero.img+'.jpg')}
style={styles.thumbnail} />
<View style={styles.rightContainer}>
<Text style={styles.title}>{hero.name}</Text>
</View>
</View>
<View style={styles.separator} />
</View>
);
一些研究,我知道後需要不會允許動態域名。我也試過uri,沒有錯誤,但沒有圖像。
{{uri: './img/hero/'+hero.img+'.jpg'}}
我的文件夾結構是這樣的:
Project
index.ios.js
hero.js
img
hero
什麼是處理這個問題的最好方式,我不希望把圖像在網絡上。
我看到了,但是手動將所有圖像添加到xcode assets資源文件夾中並不好玩:( –