react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[Image] Example issue: ImageView not loading image

Open meetwudi opened this issue 11 years ago • 43 comments

I am playing with the very basic example from Tutorial.

I wrote following code, just exactly what the tutorial did.

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 */
'use strict';

var React = require('react-native');
var {
  AppRegistry,
  Image,
  StyleSheet,
  Text,
  View,
} = React;

var MOCKED_MOVIES_DATA = [
  {title: 'Title of movie', year: '2015', posters: {thumbnail: 'http://i.imgur.com/UePbdph.jpg'}},
];

var Awesome = React.createClass({
  render: function() {
    var movie = MOCKED_MOVIES_DATA[0];
    return (
      <View style={styles.container}>
        <Text>{movie.title}</Text>
        <Text>{movie.year}</Text>
        <Image source={{uri: movie.posters.thumbnail}} 
          style={styles.thumbnail} />
      </View>
    );
  }
});

var styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  thumbnail: {
    width: 53,
    height: 81,
  },
});

AppRegistry.registerComponent('Awesome', () => Awesome);

But it turns out that the ImageView did not load the poster correctly. I changed the backgroundColor of Image to red, and I just got a red rectangle without the poster.

I checked the internet connection. I can access the image from Safari Mobile.

And I don't know if there is any way to debug this app so that I can figure out how to resolve this issue.

Any thoughts?

meetwudi avatar Mar 27 '15 01:03 meetwudi

I had this issue, and all that I needed to do was delete the old styles declaration, maybe in the tutorial we could say something like "replace the old style declaration with the new one" so that users know that a replacement is needed rather than just adding a block of code

yogurt-island-331 avatar Sep 20 '15 16:09 yogurt-island-331

I had this issue, and it was only resolved by replacing

source={{uri: movie.posters.thumbnail}}

with

source={{uri: 'http://i.imgur.com/UePbdph.jpg'}}

baumant avatar Dec 18 '15 03:12 baumant

Had this issue as well. After that I realized that my images were too huge for the screen (some 500KB each). After reducing the size (to about 1/10th of it), it worked fine.

ling-wong avatar Dec 21 '15 10:12 ling-wong

I just ran into something similar. I just tried to copy and paste from the first example here: https://facebook.github.io/react-native/docs/image.html#image

I just started a new project and assumed I didn't have the local file so I deleted the first image and kept only the second image that loads the facebook react logo from uri. This didn't work and ended up here. I tried the reset content and settings but this still did not work.

After playing around a bit more I discovered this bit of documentation https://facebook.github.io/react-native/docs/images.html#network-images that states that network images must specify size. Copying the example from this section does work.

No idea if it would have been necessary for me to Reset Content and Settings, but there does seem to be some non-working example code.

I would submit a pull request but at the moment github is giving me a 405 error when I attempt to fork the project so I figured I would post the info here for now.

kurtharriger avatar Apr 05 '16 20:04 kurtharriger

I'm having this issue. I copied the Final Source Code from the bottom of the Movie Fetcher sample app (https://facebook.github.io/react-native/docs/sample-application-movies.html) and ran it in the iPhone simulator. The list looks fine, but no images. I've tried both via xcode and the command line. Tried Reset Content and Settings, but no luck.

The image is at line 74,

<Image
  source={{uri: movie.posters.thumbnail}}
  style={styles.thumbnail}
/>

When I replace movie.posters.thumbnail with 'https://facebook.github.io/react/img/logo_og.png', the image displays. However, I tried other hard-coded images, but those didn't work either.

> react-native --version
react-native-cli: 1.0.0
react-native: 0.28.0

hectoroso avatar Jun 23 '16 04:06 hectoroso

Changing the URL to HTTPS fixed it for me (and many others). https://i.imgur.com/UePbdph.jpg

abdulsattar avatar Jun 24 '16 12:06 abdulsattar

modify Info.plist works for me Reference: https://github.com/facebook/react-native/issues/1563#issuecomment-162721129

hnaoto avatar Jun 24 '16 15:06 hnaoto

Both solutions, modify info.plist or changing url to https, resolved the issue for me. Thanks for the quick response!

hectoroso avatar Jun 24 '16 15:06 hectoroso

Here's one which worked for me 👍 changed the image source uri protocol to HTTPS from HTTP and bingo! var App = React.createClass({ render: function() { var movie = MOCKED_MOVIES_DATA[0]; return ( <Image source={{uri: 'https://i.imgur.com/UePbdph.jpg'}} style={ {width:50 ,height:50} } /> ); } });

nikhil38 avatar Jun 29 '16 17:06 nikhil38

I had same issue. I doubt that it is the new iOS HTTPS thing is the problem. I tried to change the App Transport Security Settings to Allow Arbitrary Loads to YES and it worked as expected!

flysofast avatar Jul 02 '16 02:07 flysofast

changing image url to https solves the issue. Also, if you follow up with the rest of the tutorial and fetch the data from the API you will have the same problem too. One way to solve this is to use lodash and replace http with https, like this: source={{uri: _.replace(movie.posters.thumbnail, 'http://', 'https://')}}

cpenarrieta avatar Jul 04 '16 05:07 cpenarrieta

No need to use underscore: source={{uri: movie.posters.thumbnail.replace('http://', 'https://')}}

ArthurClemens avatar Jul 05 '16 19:07 ArthurClemens

I'm running into the same issue, if you fetch the image from a website that uses HTTP it fails to fetch the image but once you change it to HTTPS it loads correctly.

fernando-sendMail avatar Jul 14 '16 04:07 fernando-sendMail

Have you tried enable Allow Arbitrary Loads when using HTTP? Hope it will work for you. info.plist -> App Transport Security Settings -> Allow Arbitrary Loads TRUE

liluo-tw avatar Jul 14 '16 04:07 liluo-tw

That would work temporarily during development - I don't want that setting in a testing/production app.

ArthurClemens avatar Jul 14 '16 08:07 ArthurClemens

I am having the same problem in android. any workaround for android?

waleedarshad-vf avatar Aug 10 '16 06:08 waleedarshad-vf

I have Horizontal ScrollView inside ListView. and some of images are loading and some are not.

waleedarshad-vf avatar Aug 10 '16 06:08 waleedarshad-vf

Changing HTTP to HTTPS does not work for me

waleedarshad-vf avatar Aug 10 '16 06:08 waleedarshad-vf

@waleedarshad-vf Try to change you Info.plist file just like @CassieLuoli said, however keep in mind that this is not an optimal solution for production. If you want this done the proper way you should check this article

fernando-sendMail avatar Aug 11 '16 05:08 fernando-sendMail

@fernando-sendMail I am on android and i don't have Info.plist in android but androidManifest.xml and it has permission already about netWork.

waleedarshad-vf avatar Aug 11 '16 07:08 waleedarshad-vf