Skip to content

Commit bca8510

Browse files
Ignigenafacebook-github-bot
authored andcommittedFeb 21, 2019
fix: prevent exception when imageName is null (#20120)
Summary: When an image source is parsed via `RCTImageFromLocalAssetURL` there seem to be certain situations in which `imageName` is empty from `RCTBundlePathForURL`. Any call to `UIImage imageNamed` with a an empty parameter will throw an exception: ``` CUICatalog: Invalid asset name supplied: '(null)' ``` In my case, the asset URL was pointing to an image in the application sandbox rather than the `NSBundle`. In this case `UIImage imageNamed` was throwing before the call to `NSData dataWithContentsOfURL` below could correctly resolve the image. This change simply skips the call to `UIImage imageNamed` if no `imageName` value is set. Pull Request resolved: #20120 Differential Revision: D14163101 Pulled By: cpojer fbshipit-source-id: ceec95c02bf21b739962ef5618947a5726ba0473
1 parent 30f1381 commit bca8510

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed
 

Diff for: ‎React/Base/RCTUtils.m

+6-4
Original file line numberDiff line numberDiff line change
@@ -700,10 +700,12 @@ BOOL RCTIsLocalAssetURL(NSURL *__nullable imageURL)
700700
}
701701

702702
UIImage *image = nil;
703-
if (bundle) {
704-
image = [UIImage imageNamed:imageName inBundle:bundle compatibleWithTraitCollection:nil];
705-
} else {
706-
image = [UIImage imageNamed:imageName];
703+
if (imageName) {
704+
if (bundle) {
705+
image = [UIImage imageNamed:imageName inBundle:bundle compatibleWithTraitCollection:nil];
706+
} else {
707+
image = [UIImage imageNamed:imageName];
708+
}
707709
}
708710

709711
if (!image) {

0 commit comments

Comments
 (0)
Please sign in to comment.