Skip to content

Commit

Permalink
Fix Image defaultSource not showing on iOS (#32172)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cristianoccazinsp authored and facebook-github-bot committed Sep 29, 2021
1 parent 04184ef commit 900210c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Libraries/Image/RCTImageView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ - (void)cancelAndClearImageLoad

[_imageLoader trackURLImageRequestDidDestroy:_loaderRequest];
_loaderRequest = nil;

if (!self.image) {
self.image = _defaultImage;
}
}

- (void)clearImageIfDetached
Expand Down
6 changes: 4 additions & 2 deletions packages/rn-tester/js/examples/Image/ImageExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ class OnPartialLoadExample extends React.Component<
}
}

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

0 comments on commit 900210c

Please sign in to comment.