From 44f2a083716205b7560bef2f09d25830e29cd0c5 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Mon, 4 Nov 2024 10:26:55 -0800 Subject: [PATCH] Add png extension only if file exist when load local image (#46971) Summary: FIxes https://github.com/facebook/react-native/issues/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: https://github.com/facebook/react-native/pull/46971 Test Plan: Demo in https://github.com/facebook/react-native/issues/46870 . Reviewed By: blakef Differential Revision: D65276409 Pulled By: cipolleschi fbshipit-source-id: 9e03a36b229f7c336632b5b76a92d9f749c59835 --- packages/react-native/Libraries/Image/RCTImageLoader.mm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/react-native/Libraries/Image/RCTImageLoader.mm b/packages/react-native/Libraries/Image/RCTImageLoader.mm index 68a12d35122..165c711d1c6 100644 --- a/packages/react-native/Libraries/Image/RCTImageLoader.mm +++ b/packages/react-native/Libraries/Image/RCTImageLoader.mm @@ -477,7 +477,10 @@ static UIImage *RCTResizeImageIfNeeded(UIImage *image, CGSize size, CGFloat scal // 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];