From 12ab2366297948a4e37d3f6409e851e6c2246f50 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Fri, 30 Jun 2017 06:54:43 -0700 Subject: [PATCH] Fix references to deprecated assets in separate bundles Reviewed By: sahrens Differential Revision: D5346879 fbshipit-source-id: 9d1008765514006deef2182e61f42a7247ea9a85 --- React/Base/RCTConvert.m | 15 +++------------ React/Base/RCTUtils.m | 14 +++++++++----- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/React/Base/RCTConvert.m b/React/Base/RCTConvert.m index 256fd854b..43ee820de 100644 --- a/React/Base/RCTConvert.m +++ b/React/Base/RCTConvert.m @@ -736,7 +736,7 @@ RCT_ENUM_CONVERTER(RCTAnimationType, (@{ // thread safe, so we'll pick the lesser of two evils here and block rather // than run the risk of crashing RCTLogWarn(@"Calling [RCTConvert UIImage:] on a background thread is not recommended"); - dispatch_sync(dispatch_get_main_queue(), ^{ + RCTUnsafeExecuteOnMainQueueSync(^{ image = [self UIImage:json]; }); return image; @@ -745,18 +745,9 @@ RCT_ENUM_CONVERTER(RCTAnimationType, (@{ NSURL *URL = imageSource.request.URL; NSString *scheme = URL.scheme.lowercaseString; if ([scheme isEqualToString:@"file"]) { - NSString *assetName = RCTBundlePathForURL(URL); - image = assetName ? [UIImage imageNamed:assetName] : nil; + image = RCTImageFromLocalAssetURL(URL); if (!image) { - // Attempt to load from the file system - NSString *filePath = URL.path; - if (filePath.pathExtension.length == 0) { - filePath = [filePath stringByAppendingPathExtension:@"png"]; - } - image = [UIImage imageWithContentsOfFile:filePath]; - if (!image) { - RCTLogConvertError(json, @"an image. File not found."); - } + RCTLogConvertError(json, @"an image. File not found."); } } else if ([scheme isEqualToString:@"data"]) { image = [UIImage imageWithData:[NSData dataWithContentsOfURL:URL]]; diff --git a/React/Base/RCTUtils.m b/React/Base/RCTUtils.m index ab49299d3..7844508b3 100644 --- a/React/Base/RCTUtils.m +++ b/React/Base/RCTUtils.m @@ -643,10 +643,6 @@ static NSBundle *bundleForPath(NSString *key) UIImage *__nullable RCTImageFromLocalAssetURL(NSURL *imageURL) { - if (!RCTIsLocalAssetURL(imageURL)) { - return nil; - } - NSString *imageName = RCTBundlePathForURL(imageURL); NSBundle *bundle = nil; @@ -665,6 +661,15 @@ UIImage *__nullable RCTImageFromLocalAssetURL(NSURL *imageURL) image = [UIImage imageNamed:imageName]; } + if (!image) { + // Attempt to load from the file system + NSString *filePath = imageURL.path; + if (filePath.pathExtension.length == 0) { + filePath = [filePath stringByAppendingPathExtension:@"png"]; + } + image = [UIImage imageWithContentsOfFile:filePath]; + } + if (!image && !bundle) { // We did not find the image in the mainBundle, check in other shipped frameworks. NSArray *possibleFrameworks = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:[[NSBundle mainBundle] privateFrameworksURL] @@ -680,7 +685,6 @@ UIImage *__nullable RCTImageFromLocalAssetURL(NSURL *imageURL) } } } - return image; }