编辑:只在发布时不工作。
我使用的是react native 0.60.3版本。一年前做了一个本地图片的应用程序,它工作得很好。我更新Xcode到11版本,旧的代码和图片也能正常工作。我尝试为黑暗模式添加新的图像,但图像不显示,没有错误,只有空白处。在代码中使用来自js文件的图片,如:"url":require("../images/page1.png")
.
图片被添加到复制捆绑资源。
我尝试用命令.和复制assets和main.js。npx react-native bundle --entry-file='index.ios.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios' --assets-dest='./ios
并将assets和main.jsbundle复制到Xcode中,得到的结果是一样的,之前我在XCode中没有assets文件夹,图片一直在copy bundle资源中,旧的图片可以用(一年前添加的),新的图片不能用。我错过了什么吗?我没有错误,不知道如何解决这个问题。
我的代码。
<CustomImage
width={getImgWidth} height={getImgHeight}
lightpath={it.url}
darkpath={it.urldark}
darkmode={theme.darkmode} />
CustomImage.js
const CustomImage = (props) => {
return (
<View style={{ width: props.width, height: props.height }}>
{props.darkmode ? (
<Image
resizeMode="contain"
style={{ width: props.width, height: props.height }}
source={props.darkpath}
/>
) : (
<Image
resizeMode="contain"
style={{ width: props.width, height: props.height }}
source={props.lightpath}
/>
)}
</View>
);
};
自 props.darkpath = require("../images/page1.png")
你能不能试试。
<Image
resizeMode="contain"
style={{ width: props.width, height: props.height }}
source={`${props.darkpath}`}
/>