From d5c6b9834007f7db9452b53bd4ff98586ee88674 Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Tue, 22 May 2018 15:50:57 -0700 Subject: [PATCH] [fix] Image loading callbacks when mounting cached image --- packages/react-native-web/src/exports/Image/index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/react-native-web/src/exports/Image/index.js b/packages/react-native-web/src/exports/Image/index.js index ebc5ac74..9cc16f83 100644 --- a/packages/react-native-web/src/exports/Image/index.js +++ b/packages/react-native-web/src/exports/Image/index.js @@ -122,6 +122,7 @@ class Image extends Component<*, State> { static resizeMode = ImageResizeMode; + _imageRef = null; _imageRequestId = null; _imageState = null; _isMounted = false; @@ -134,7 +135,6 @@ class Image extends Component<*, State> { const shouldDisplaySource = ImageUriCache.has(uri); this.state = { shouldDisplaySource }; this._imageState = getImageState(uri, shouldDisplaySource); - shouldDisplaySource && ImageUriCache.add(uri); } componentDidMount() { @@ -142,8 +142,7 @@ class Image extends Component<*, State> { if (this._imageState === STATUS_PENDING) { this._createImageLoader(); } else if (this._imageState === STATUS_LOADED) { - const { onLoad } = this.props; - onLoad && onLoad(); + this._onLoad({ target: this._imageRef }); } } @@ -218,6 +217,7 @@ class Image extends Component<*, State> { ? createElement('img', { alt: accessibilityLabel || '', draggable, + ref: this._setImageRef, src: displayImage, style: styles.img }) @@ -313,6 +313,10 @@ class Image extends Component<*, State> { } } + _setImageRef = ref => { + this._imageRef = ref; + }; + _updateImageState(status) { this._imageState = status; const shouldDisplaySource =