Permalink
Browse files

RCTLocalAssetImageLoader: Add searching shipped frameworks beyond mai…

…nBundle

Reviewed By: javache

Differential Revision: D4715608

fbshipit-source-id: 5cb2febf543e2ff6e30d0c6d8737de9a2cce2383
  • Loading branch information...
Jeff Thomas authored and facebook-github-bot committed Mar 20, 2017
1 parent c451dd6 commit 439889262c9055faa3582a18441029ea063a7a6b
Showing with 22 additions and 3 deletions.
  1. +22 −3 React/Base/RCTUtils.m
View
@@ -637,7 +637,7 @@ BOOL RCTIsLocalAssetURL(NSURL *__nullable imageURL)
NSString *imageName = RCTBundlePathForURL(imageURL);
NSBundle *bundle;
NSBundle *bundle = nil;
NSArray *imagePathComponents = [imageName pathComponents];
if ([imagePathComponents count] > 1 &&
[[[imagePathComponents firstObject] pathExtension] isEqualToString:@"bundle"]) {
@@ -646,11 +646,30 @@ BOOL RCTIsLocalAssetURL(NSURL *__nullable imageURL)
imageName = [imageName substringFromIndex:(bundlePath.length + 1)];
}
UIImage *image = nil;
if (bundle) {
return [UIImage imageNamed:imageName inBundle:bundle compatibleWithTraitCollection:nil];
image = [UIImage imageNamed:imageName inBundle:bundle compatibleWithTraitCollection:nil];
} else {
return [UIImage imageNamed:imageName];
image = [UIImage imageNamed:imageName];
}
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]
includingPropertiesForKeys:@[]
options:nil
error:nil];
for (NSURL *frameworkURL in possibleFrameworks) {
bundle = [NSBundle bundleWithURL:frameworkURL];
image = [UIImage imageNamed:imageName inBundle:bundle compatibleWithTraitCollection:nil];
if (image) {
RCTLogWarn(@"Image %@ not found in mainBundle, but found in %@", imageName, bundle);
break;
}
}
}
return image;
}
RCT_EXTERN NSString *__nullable RCTTempFilePath(NSString *extension, NSError **error)

0 comments on commit 4398892

Please sign in to comment.