Skip to content

Commit 900210c

Browse files
Fix Image defaultSource not showing on iOS (#32172)
Summary: Fix Image defaultSource not showing on iOS. This bug was introduced somewhere between RN 0.63 and 0.65. On iOS, defaultSource does not show while the image is being downloaded, only if it fails or there's no internet. ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [iOS] [Fixed] - Fix Image defaultSource not showing on iOS Pull Request resolved: #32172 Test Plan: Ran both debug and release builds on an iPhone 12 pro (iOS 14.6) Reviewed By: sammy-SC Differential Revision: D30822805 Pulled By: lunaleaps fbshipit-source-id: c4ef18723a8311ef3be1d7ae25ff3c205e8fff62
1 parent 04184ef commit 900210c

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Libraries/Image/RCTImageView.mm

+4
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ - (void)cancelAndClearImageLoad
234234

235235
[_imageLoader trackURLImageRequestDidDestroy:_loaderRequest];
236236
_loaderRequest = nil;
237+
238+
if (!self.image) {
239+
self.image = _defaultImage;
240+
}
237241
}
238242

239243
- (void)clearImageIfDetached

packages/rn-tester/js/examples/Image/ImageExample.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ class OnPartialLoadExample extends React.Component<
585585
}
586586
}
587587

588-
const fullImage = {
588+
const fullImage: ImageSource = {
589589
uri: 'https://www.facebook.com/ads/pics/successstories.png',
590590
};
591591
const smallImage = {
@@ -747,7 +747,9 @@ exports.examples = [
747747
<Image
748748
defaultSource={require('../../assets/bunny.png')}
749749
source={{
750-
uri: 'https://origami.design/public/images/bird-logo.png',
750+
// Note: Use a large image and bust cache so we can in fact
751+
// visualize the `defaultSource` image.
752+
uri: fullImage.uri + '?cacheBust=notinCache' + Date.now(),
751753
}}
752754
style={styles.base}
753755
/>

0 commit comments

Comments
 (0)