[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?
Sometimes if you lose internet connection and get it back up, the simulator will get stuck with no internet. Can you try to kill the simulator and rebuild?
@vjeux Thanks. I restarted the simulator, rebuild the app but it does not work :( Any approach I can inspect the internet status?
@tjwudi if it is a simulator problem try completely resetting it (as if it were a new iPhone). Reset Content and Settings or something like that I believe.
@ide Resetting does work, thanks a lot! I wonder how come the issue, though.
I had the same problem, and was quite confused for many minutes, but solved it by doing "Reset content and settings". Not sure if this is the Simulator's fault or React's, but it should probably be fixed soon in order not to scare new people away, it is after all the very first tutorial in the official docs. :)
If anyone in this thread has any idea how to solve this problem (not workaround by resetting) that would be awesome
Can one of the repo owners re-open the issue if it's still an issue? ;)
JG
@moduscreate
:: sent from my mobile device ::
On Apr 8, 2015, at 11:01, Christopher Chedeau [email protected] wrote:
If anyone in this thread has any idea how to solve this problem (not workaround by resetting) that would be awesome
— Reply to this email directly or view it on GitHub.
Just experienced the issue. Resetting still works. @t4t5 has a great point about it being a bug in step 2 of the tutorial.
Solved by "Reset content and settings".I was wondering if something wrong with the url.
Have experienced the same problem on device, but have not looked into it, assumed it might be a problem with caching a failed download.
I'm probably hitting this too. Both in simulator and device. I have a ListView of images and the images won't load many times. Doing a complete Reset on the Simulator seems to make it work for a while.
Same here
Same problem on device~
Same issue. Opening up Charles proxy reveals that no request to the image is being made. Maybe the Image component thinks it has the image cached?
Appending '?t=' + Math.round(new Date().getTime() / 1000) to the uri appears to make the image load but this obviously disables caching.
How to check <Image /> was finished loading?
I am not sure if this is what I am running into but here is my issue. I have a news feed like list view with images, when i add a new item to the feed and refresh it, a lot of the times the new feed item will show with the old image. So I wrapped
componentWillReceiveProps(nextProps) {
let image = (nextProps.image !== this.state.image) ? `${nextProps.picture}?t=${new Date().getTime()}` : nextProps.picture;
this.setState({image: image});
}
shouldComponentUpdate(nextProps) {
return (nextProps.picture !== this.props.picture);
}
This fixes this problem for me on the simulator only, for some reason the device just doesn't update the image at all. Is this similar or should I create a new issue?
Just tidying up old issues. Any update on this @nicklockwood?
Not sure. The imageview component has been rewritten since this was raised, but I don't know if this specific issue has been fixed.
Thanks @nicklockwood. Is this still an issue @tjwudi?
In my case, the image does not show even resetting the simulator but just leave a background color. I'm using react-native 10.0
----- Update! ----- OK, it's my own fault. When I looked at my code after a week or so, I found I had a typo. I wrote the prop 'source' of Image as 'srouce'. It works perfectly when I corrected it. Sorry for any convenience!