Skip to content

Commit

Permalink
fix: prevent exception when imageName is null (#20120)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Ignigena authored and facebook-github-bot committed Feb 21, 2019
1 parent 30f1381 commit bca8510
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions React/Base/RCTUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -700,10 +700,12 @@ BOOL RCTIsLocalAssetURL(NSURL *__nullable imageURL)
}

UIImage *image = nil;
if (bundle) {
image = [UIImage imageNamed:imageName inBundle:bundle compatibleWithTraitCollection:nil];
} else {
image = [UIImage imageNamed:imageName];
if (imageName) {
if (bundle) {
image = [UIImage imageNamed:imageName inBundle:bundle compatibleWithTraitCollection:nil];
} else {
image = [UIImage imageNamed:imageName];
}
}

if (!image) {
Expand Down

0 comments on commit bca8510

Please sign in to comment.