From 5683932862ab870e735342342c68e03fb5ca9e09 Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Thu, 16 Sep 2021 23:13:05 -0700 Subject: [PATCH] RN: Fix NSInvalidArgumentException for Invalid Font Family Name 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 --- React/Views/RCTFont.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/React/Views/RCTFont.mm b/React/Views/RCTFont.mm index 7a8cbbb19abe01..549adca51b192e 100644 --- a/React/Views/RCTFont.mm +++ b/React/Views/RCTFont.mm @@ -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;