我下面的代碼接受 inputPhotoLocation 作為道具。inputPhotoLocation 包含影像源位置串列(已從包含串列的檔案中檢索)。我需要一種方法將這些傳遞給我的影像源。我已經能夠成功地直接在文本框中傳遞位置。
function SelectionBoxComponent({inputPhotoLocation, inputText, onPress}) {
return (
<TouchableWithoutFeedback onPress={onPress}>
<View style={styles.box}>
<View style={styles.circularPhoto}>
<Image style={{height:"100%", width:"100%", borderRadius:70,
borderWidth:0, source={require(inputPhotoLocation)}}} ></Image> //here i need to insert the list items
</View>
<AppText style={styles.textStyle} onPress={console.log(inputText)} >
{inputText}</AppText>
</View>
</TouchableWithoutFeedback>
我的 inputPhotoLocation 道具包含這個
./assets/GroupImages/football.jpg
../assets/GroupImages/valley.jpg
../assets/GroupImages/usa.jpg
../assets/GroupImages/playstation.jpg
../assets/GroupImages/pc.jpg
我能夠成功地將這些位置作為文本輸出傳遞。但是,我不知道如何在影像源中傳遞這些。謝謝!
uj5u.com熱心網友回復:
<Image
style={{
height: '100%',
width: '100%',
borderRadius: 70,
borderWidth: 0,
source={require(inputPhotoLocation) // The source prop is not a style prop
}}></Image>
<Image
source={require(inputPhotoLocation) // The source prop is Image prop
style={{
height: '100%',
width: '100%',
borderRadius: 70,
borderWidth: 0
}}></Image>
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/328988.html
標籤:javascript 反应 列表 反应原生 反应还原
