[Image] Example issue: ImageView not loading image
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?
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
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'}}
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.
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.
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
Changing the URL to HTTPS fixed it for me (and many others). https://i.imgur.com/UePbdph.jpg
modify Info.plist works for me Reference: https://github.com/facebook/react-native/issues/1563#issuecomment-162721129
Both solutions, modify info.plist or changing url to https, resolved the issue for me. Thanks for the quick response!
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 (
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!
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://')}}
No need to use underscore: source={{uri: movie.posters.thumbnail.replace('http://', 'https://')}}
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.
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
That would work temporarily during development - I don't want that setting in a testing/production app.
I am having the same problem in android. any workaround for android?
I have Horizontal ScrollView inside ListView. and some of images are loading and some are not.
Changing HTTP to HTTPS does not work for me
@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 I am on android and i don't have Info.plist in android but androidManifest.xml and it has permission already about netWork.