mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-26 13:25:51 +08:00
RCTLocalAssetImageLoader: Add searching shipped frameworks beyond mainBundle
Reviewed By: javache Differential Revision: D4715608 fbshipit-source-id: 5cb2febf543e2ff6e30d0c6d8737de9a2cce2383
This commit is contained in:
committed by
Facebook Github Bot
parent
c451dd6cce
commit
439889262c
@@ -637,7 +637,7 @@ UIImage *RCTImageFromLocalAssetURL(NSURL *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 @@ UIImage *RCTImageFromLocalAssetURL(NSURL *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)
|
||||
|
||||
Reference in New Issue
Block a user