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

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 avatar Mar 27 '15 01:03 vjeux

@vjeux Thanks. I restarted the simulator, rebuild the app but it does not work :( Any approach I can inspect the internet status?

meetwudi avatar Mar 27 '15 01:03 meetwudi

@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 avatar Mar 27 '15 01:03 ide

@ide Resetting does work, thanks a lot! I wonder how come the issue, though.

meetwudi avatar Mar 27 '15 01:03 meetwudi

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. :)

t4t5 avatar Apr 08 '15 13:04 t4t5

If anyone in this thread has any idea how to solve this problem (not workaround by resetting) that would be awesome

vjeux avatar Apr 08 '15 15:04 vjeux

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.

jaygarcia avatar Apr 08 '15 15:04 jaygarcia

Just experienced the issue. Resetting still works. @t4t5 has a great point about it being a bug in step 2 of the tutorial.

SizeSeeker avatar Apr 10 '15 21:04 SizeSeeker

Solved by "Reset content and settings".I was wondering if something wrong with the url.

ReadingSteiner avatar Apr 19 '15 08:04 ReadingSteiner

Have experienced the same problem on device, but have not looked into it, assumed it might be a problem with caching a failed download.

drkibitz avatar Apr 19 '15 08:04 drkibitz

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.

paramaggarwal avatar Apr 26 '15 02:04 paramaggarwal

Same here

mondras avatar May 03 '15 16:05 mondras

Same problem on device~

asamoon avatar May 09 '15 16:05 asamoon

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.

amccloud avatar May 11 '15 03:05 amccloud

How to check <Image /> was finished loading?

asamoon avatar May 12 '15 05:05 asamoon

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 and took over shouldComponentUpdate, I have something like this

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?

josebalius avatar Jun 30 '15 16:06 josebalius

Just tidying up old issues. Any update on this @nicklockwood?

MossP avatar Jul 20 '15 19:07 MossP

Not sure. The imageview component has been rewritten since this was raised, but I don't know if this specific issue has been fixed.

nicklockwood avatar Jul 20 '15 19:07 nicklockwood

Thanks @nicklockwood. Is this still an issue @tjwudi?

MossP avatar Jul 20 '15 19:07 MossP

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!

f15gdsy avatar Aug 31 '15 15:08 f15gdsy