Can't show Image in React Native

后端 未结 13 2621
半阙折子戏
半阙折子戏 2020-12-05 23:31

I\'m using react-native 0.28.0

I\'m trying to show an image on iPhone simulator according to this tutorial: http://www.appcoda.com/react-native-introduction/



        
相关标签:
13条回答
  • 2020-12-05 23:51

    To anyone getting here, if the accepted answer didn't work for you, make sure your image has proper styling. For uri imported images, you'll need to set both height and width.

    0 讨论(0)
  • 2020-12-05 23:57

    Side note on this issue. Upgrading from React Native 0.63.0 to 0.63.2 fixes an issue where remote images do not display on iOS 14 on device. I found this thread while searching for answers on it, so thought it might help anyone else in the same boat. Just upgrade. :)

    0 讨论(0)
  • 2020-12-06 00:00

    I have uninstalled the previously installed app and it started working.

    0 讨论(0)
  • 2020-12-06 00:01

    My issue was in path. react-native-fs returns path like /storage/emulated/0/Android/data/com.blah/blah.jpeg but Image components requires it to be file:///storage/emulated/0/Android/data/com.blah/blah.jpeg

    0 讨论(0)
  • 2020-12-06 00:02

    In addition to Jonathan Stellwag's answer, the 1st solution only works if the URI is using https, or by setting the App Transport Security.

    See Can't show Image by URI in React Native iOS Simulator

    0 讨论(0)
  • 2020-12-06 00:03

    The issue I had coming from web was the uri parameter which I thought was url

    Incorrect: <Image style={styles.image} source={ { url: product.image } }/>

    Correct: <Image style={styles.image} source={ { uri: product.image } }/>

    Plus you have to set width and height to the image element

    It took me a while to figure out

    0 讨论(0)
提交回复
热议问题