Fix references to deprecated assets in separate bundles

Reviewed By: sahrens

Differential Revision: D5346879

fbshipit-source-id: 9d1008765514006deef2182e61f42a7247ea9a85
This commit is contained in:
Pieter De Baets 2017-06-30 06:54:43 -07:00 committed by Facebook Github Bot
parent d494282fd1
commit 12ab236629
2 changed files with 12 additions and 17 deletions

View File

@ -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]];

View File

@ -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<NSURL *> *possibleFrameworks = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:[[NSBundle mainBundle] privateFrameworksURL]
@ -680,7 +685,6 @@ UIImage *__nullable RCTImageFromLocalAssetURL(NSURL *imageURL)
}
}
}
return image;
}