Skip to content

Commit

Permalink
Add png extension only if file exist when load local image (#46971)
Browse files Browse the repository at this point in the history
Summary:
FIxes #46870.

To avoid many breaking changes, I modified the logic to add the PNG extension only if the file exists.

## Changelog:

[IOS] [FIXED] - Add png extension only if file exist when load local image

Pull Request resolved: #46971

Test Plan: Demo in #46870 .

Reviewed By: blakef

Differential Revision: D65276409

Pulled By: cipolleschi

fbshipit-source-id: 9e03a36b229f7c336632b5b76a92d9f749c59835
  • Loading branch information
zhongwuzw authored and facebook-github-bot committed Nov 4, 2024
1 parent d755029 commit 44f2a08
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/react-native/Libraries/Image/RCTImageLoader.mm
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,10 @@ - (RCTImageURLLoaderRequest *)_loadImageOrDataWithURLRequest:(NSURLRequest *)req

// Add missing png extension
if (request.URL.fileURL && request.URL.pathExtension.length == 0) {
mutableRequest.URL = [request.URL URLByAppendingPathExtension:@"png"];
NSURL *pngRequestURL = [request.URL URLByAppendingPathExtension:@"png"];
if ([[NSFileManager defaultManager] fileExistsAtPath:pngRequestURL.path]) {
mutableRequest.URL = pngRequestURL;
}
}
if (_redirectDelegate != nil) {
mutableRequest.URL = [_redirectDelegate redirectAssetsURL:mutableRequest.URL];
Expand Down

0 comments on commit 44f2a08

Please sign in to comment.