mirror of
https://github.com/zhigang1992/react-native-web.git
synced 2026-01-12 22:51:09 +08:00
[fix] Image loading callbacks when mounting cached image
This commit is contained in:
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user