Skip to content

Commit

Permalink
Fix references to deprecated assets in separate bundles
Browse files Browse the repository at this point in the history
Reviewed By: sahrens

Differential Revision: D5346879

fbshipit-source-id: 9d1008765514006deef2182e61f42a7247ea9a85
  • Loading branch information
javache authored and facebook-github-bot committed Jun 30, 2017
1 parent d494282 commit 12ab236
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
15 changes: 3 additions & 12 deletions React/Base/RCTConvert.m
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ + (UIImage *)UIImage:(id)json
// 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;
Expand All @@ -745,18 +745,9 @@ + (UIImage *)UIImage:(id)json
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]];
Expand Down
14 changes: 9 additions & 5 deletions React/Base/RCTUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -643,10 +643,6 @@ BOOL RCTIsLocalAssetURL(NSURL *__nullable imageURL)

UIImage *__nullable RCTImageFromLocalAssetURL(NSURL *imageURL)
{
if (!RCTIsLocalAssetURL(imageURL)) {
return nil;
}

NSString *imageName = RCTBundlePathForURL(imageURL);

NSBundle *bundle = nil;
Expand All @@ -665,6 +661,15 @@ BOOL RCTIsLocalAssetURL(NSURL *__nullable 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]
Expand All @@ -680,7 +685,6 @@ BOOL RCTIsLocalAssetURL(NSURL *__nullable imageURL)
}
}
}

return image;
}

Expand Down

0 comments on commit 12ab236

Please # to comment.