私は反応ネイティブで作業していますが、私は自分のButtonのクラスを作成しています。ボタンには画像が含まれています。ここで私は私の視点で私のボタンを減速させた。レスポンスネイティブのvarを含むvarを要求する
var imageUrl = { //this is a var from a JSON object there could be more than 20 different images
normal: "../assets/images/emoticons/1.png",
selected: "../assets/images/emoticons/1-selected.png"
}
<Button key={index}
selected={true}
onPress={onSelect}
imageUrl={imageUrl} />
「ボタン」クラスでは、ボタンに画像を設定する_renderImage関数を作成しました。
_renderImage(imageUrl){
let image = (selected === true) ? require(imageUrl.normal) : require(imageUrl.selected); //get the right image url
console.log('../assets/images/emoticons/1.png'); //logs '../assets/images/emoticons/1.png'
console.log(typeof('../assets/images/emoticons/1.png')); //logs string
console.log(image); //logs '../assets/images/emoticons/1.png'
console.log(typeof(image)); //logs string
return (
<Image source={require(image)} />
);
}
この関数はエラーを返します。ここのスクリーンショットでは、エラーを見ることができます。
iマニュアル設定時<Image source= require('../assets/images/emoticons/1.png)} />
イメージをレンダリングするとき。したがって、画像はこの場所に存在します。このような
同様の質問には私の問題を解決していません: Trouble requiring image module in React Native