如何使用React Native和Expo显示图像?

时间:2018-04-14 23:03:27

标签: react-native expo create-react-native-app

我正在制作我的第一个本机项目,我使用了create-react-native-app命令来设置所有内容。但是,当我尝试在Expo中显示图像时,它会给出一条错误消息,指出它无法找到png文件。我目前将文件放在'./img/record_video.png'下(它只是一个我将用作按钮的图标)。 Here's my project layout and the code I'm using to call it

也就是说,我正在使用<Image source={require('./img/record_video.png')} />来调用该文件。

This is the error message I receive on my phone from the Expo app简而言之就是undefined Unable to resolve module './img/record_video.png' from C:\Users\ddude\Desktop\AwesomeProject\App.js':The module './img/record_video.png' could not be found from 'C:\Users\ddude\Desktop\AwesomeProject\App.js'. Indeed, none of these files exist: *'record_video.png' *'C:\Users\ddude\Desktop\AwesomeProject\img\record_video.png\index(.native||.android.js|.native.js|.js|.android.json|.native.json|.json)'

我不确定是不是我正在使用Expo并且它没有正确导出到手机,或者它是否需要在特别命名的文件夹中。任何帮助将不胜感激,谢谢!

1 个答案:

答案 0 :(得分:0)

删除下划线&amp;将图像资源重命名为record-video.png,record-voice.png和convert-to-text.png。重启包管理器并尝试。

  

另一个观察我没有在img文件夹中看到图像record_audio.png   按照第二行的要求。

希望它有所帮助。