Skip to content

Commit

Permalink
RN: Fix NSInvalidArgumentException for Invalid Font Family Name
Browse files Browse the repository at this point in the history
Summary:
We observed that in certain production scenarios, `[UIFont fontNamesForFamilyName:familyName]` returns `nil`.

This is problematic because we cannot insert `nil` (which is not an object type) into `NSCache`. Currently, this is causing `NSInvalidArgumentException` to be thrown.

This fix works around the problem by guarding against `nil`.

Changelog:
[iOS][Fixed] - Fix NSInvalidArgumentException for invalid font family names.

Reviewed By: fkgozali

Differential Revision: D31011394

fbshipit-source-id: a9eb9ce69efd832acca65787c665fcbb7b42a795
  • Loading branch information
yungsters authored and facebook-github-bot committed Sep 17, 2021
1 parent b0c8a4e commit 5683932
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion React/Views/RCTFont.mm
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ struct __attribute__((__packed__)) CacheKey {

auto names = [cache objectForKey:familyName];
if (!names) {
names = [UIFont fontNamesForFamilyName:familyName];
names = [UIFont fontNamesForFamilyName:familyName] ?: [NSArray new];
[cache setObject:names forKey:familyName];
}
return names;
Expand Down

0 comments on commit 5683932

Please sign in to comment.