30

I have the following code below, where the Image component encompasses two Image component.

  <View style={styles.container} >
    <Image
      style={{width: 50, height: 50}}
      source={{uri: 'https://facebook.github.io/react/img/logo_og.png'}}
    />
          <Image
      style={{width: 50, height: 50}}
      source={{uri: 'http://lghttp.24811.nexcesscdn.net/80B00B/qpb/media/catalog/product/cache/11/image/439x334/9df78eab33525d08d6e5fb8d27136e95/q/w/qw_neverdonejoggers_p_.png'}}
    />
  </View>

For the first github URL it renders the img logo correctly as expected. However for the second Image it doesn't render the source: qw_neverdonejoggers_p_.png

Which leads me to the conclusion that something wrong URL, however clicking on the URL correctly load the Img:

http://lghttp.24811.nexcesscdn.net/80B00B/qpb/media/catalog/product/cache/11/image/439x334/9df78eab33525d08d6e5fb8d27136e95/q/w/qw_neverdonejoggers_p_.png

I attempted to replicate the issue here, https://rnplay.org/apps/_dQXXw but it renders both the images properly.

So its only on the local my computer that for some reason I can render second image ?

Using: "react": "15.4.1", "react-native": "^0.39.2",

Shivam Sinha
  • 4,924
  • 7
  • 43
  • 65

5 Answers5

18

Andrés' answer is somewhat correct, but it does not address the exact cause of the problem, and that is iOS' App Transport Security. iOS does not allow plaintext requests (http) by default, and so you need to define a 'whitelist' of URLs that can be allowed to override this particular protection mechanism. You have that list already set up so that your app can connect to localhost during development,, so just add new entries to it. You can see how to do so in this answer. Of course, this only works if you know the list of URLs in advance, which might not suit your needs. In that case, have a look at this article.

Community
  • 1
  • 1
martinarroyo
  • 9,389
  • 3
  • 38
  • 75
12

uri only works with https. In Android it should work fine with either http or https.

You will find further information here.

Andrés Andrade
  • 2,213
  • 2
  • 18
  • 23
7

Guys there is an issue with Image component is that if first time initialize the component with source={{uri : 'some link'}} it may not work (at least not for me when I fetch image from HTTPS URL from Firebase storage). The trick is you have to trigger a change to source props like first you need to keep source to source={undefined} and then change to source={{uri : 'some link'}}. Hope it would help someone

  • I needed this. Do you know why this is happening? I'm assuming a recent update issue with something since this is the first I've seen of needing to do this. – Dwigt Apr 28 '22 at 12:54
  • Thanks @Nishain de Silva, can you recommend how to trigger the change to source's prop? – djangodev Jul 11 '22 at 21:12
  • for me I initially kept the prop to undefined and then changed the value to a string source – Nishain de Silva Aug 18 '22 at 05:58
6

Aside issue with HTTPS, make sure you set the width and height of the Image

aphoe
  • 2,586
  • 1
  • 27
  • 31
1

How i make Image source with http or https url work is by resetting the android emulator am using.

You can clear the emulator by opening the android studio then click on tools tab at the top bar select AVD Manager once it open Select the emulator you are using, right click on it then select wipe data. Once that process is completed, open cmd or terminal at the root of your react-native project $ npx react-native run-android

Alabi Temitope
  • 405
  • 5
  • 16