From 456a9847225eab8abca339b5c3bbb59ea3bcc4da Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Fri, 15 Feb 2019 02:36:42 -0800 Subject: [PATCH] Fix image wrong scale factor when load image from file system (#23446) Summary: Regression, fix image load from `~/Library` not respect scale factor. Fixes #22383 , the bug comes from [Clean up some URL path handling](https://github.com/facebook/react-native/commit/998197f444aca06cde0d5258469b3d314f8ea8b9). [iOS] [Fixed] - Fix image wrong scale factor when load image from file system Pull Request resolved: https://github.com/facebook/react-native/pull/23446 Differential Revision: D14099614 Pulled By: cpojer fbshipit-source-id: eb2267b195a05eb70cdc4671536a4c1d47fb03e2 --- React/Base/RCTUtils.m | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/React/Base/RCTUtils.m b/React/Base/RCTUtils.m index 44e1e7fe5c1730..37fff6a2a530e0 100644 --- a/React/Base/RCTUtils.m +++ b/React/Base/RCTUtils.m @@ -708,13 +708,11 @@ BOOL RCTIsLocalAssetURL(NSURL *__nullable imageURL) if (!image) { // Attempt to load from the file system - NSData *fileData; - if (imageURL.pathExtension.length == 0) { - fileData = [NSData dataWithContentsOfURL:[imageURL URLByAppendingPathExtension:@"png"]]; - } else { - fileData = [NSData dataWithContentsOfURL:imageURL]; + NSString *filePath = [NSString stringWithUTF8String:[imageURL fileSystemRepresentation]]; + if (filePath.pathExtension.length == 0) { + filePath = [filePath stringByAppendingPathExtension:@"png"]; } - image = [UIImage imageWithData:fileData]; + image = [UIImage imageWithContentsOfFile:filePath]; } if (!image && !bundle) {