Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails when trying to load image from uri in Android #3

Closed
saeed2402 opened this issue Dec 27, 2016 · 4 comments
Closed

Fails when trying to load image from uri in Android #3

saeed2402 opened this issue Dec 27, 2016 · 4 comments
Labels

Comments

@saeed2402
Copy link

saeed2402 commented Dec 27, 2016

Hi,
I get this error:
image

When I try to load image from a uri like this:

<View >

                                <ImageViewer
                                    disabled={false} // by default
                                    source={{ uri: 'http://www.menshealth.com/sites/menshealth.com/files/styles/slideshow-desktop/public/images/slideshow2/beer-intro.jpg?itok=hhBQBwWj' }}
                                    doubleTapEnabled={true} // by default double tap will zoom image
                                    onMove={(e, gestureState) => null}
                                    onPress={(opening) => console.log(opening)}
                                    mainImageStyle={styles.commentImage}
                                    zoomedImageStyle={styles.zoomedImageStyle}
                                    mainImageProps={{
                                        resizeMode: 'contain'
                                    }}
                                    zoomedImageProps={{
                                        resizeMode: 'contain'
                                    }}
                                />

                        </View>

Anything I am missing here?
I get below warning as well, not sure if it is related or not:
image

@saeed2402
Copy link
Author

I changed below function in ImageViewer.js and it worked:

componentWillMount() {
    const { source } = this.props;

    this.state.layout.x.addListener((animated) => this.handleLayoutChange(animated, LAYOUT_ENUM.X));
    this.state.layout.y.addListener((animated) => this.handleLayoutChange(animated, LAYOUT_ENUM.Y));

    this.panResponder = PanResponder.create({
      onStartShouldSetPanResponder: this.handleSetPanResponder,
      onMoveShouldSetPanResponder: () => true,
      onPanResponderMove: this.handleMove,
      onPanResponderRelease: this.handleRelease,
      onPanResponderTerminate: this.handleRelease
    });

    if (typeof source === 'object' && typeof source.uri === 'string') {
      var commentImageURL = this.props.source.uri;
      Image.prefetch(commentImageURL);
      Image.getSize(commentImageURL, (width, height) => {
        this._imageSize = { width, height };
      });
    }
  }

@shahen94
Copy link
Owner

shahen94 commented Dec 28, 2016

@saeed2402 Thank you for reporting. If you want you can open submit PR. I'll check it today in the evening.

EDITED: Yes you're right, prefetch requires string uri instead of the object.
https://github.com/facebook/react-native/blob/84553ebf06425771f07ab630aa16b8007f2f32bb/Libraries/Image/Image.ios.js#L317

Thanks !

@shahen94 shahen94 added the bug label Dec 29, 2016
@saeed2402
Copy link
Author

Thanks for confirming.
How about the warning? How can I get rid of it? I copied and pasted the code from your example, not sure what it is complaining about

shahen94 added a commit that referenced this issue Dec 30, 2016
@shahen94
Copy link
Owner

@saeed2402 Please install 0.9.10 version.

I'm going to close this issue since it has been fixed.
Feel free to re-open this if your issue is not resolved yet.

Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants