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

fix display problems when image fails to load #25969

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Libraries/Image/RCTImageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,14 @@ - (void)imageLoaderLoadedImage:(UIImage *)loadedImage error:(NSError *)error for
}

if (error) {
if (_pendingImageSource.request && _imageSource.request && ![_pendingImageSource.request.URL.absoluteString isEqual: _imageSource.request.URL.absoluteString]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain me why this condition is necessary? I am having hard time understanding why it is needed.

Otherwise
You can get rid of . absoluteString as NSURL has isEqual defined (https://developer.apple.com/documentation/foundation/nsurl/1806686-isequal?language=objc).

Also I don't think we have to check whether _pendingImageSource.request and _imageSource.request are nils.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the Image should really show whether the image is loaded successfully. If the loading fails and the URL is not equal to the previous one, then the previous image should not be displayed again, because the developer expects to display the new image, But the new image fails to load. . Usually developers can use onError's callbacks to handle failures, but when the developer doesn't handle the error, the image displayed is actually wrong.

Also, thank you for your suggestion. I got a new skill : )

RCTExecuteOnMainQueue(^{
[self.layer removeAnimationForKey:@"contents"];
self.image = loadedImage;
self->_imageSource = source;
self->_pendingImageSource = nil;
});
}
if (_onError) {
_onError(@{ @"error": error.localizedDescription });
}
Expand Down