From 1a875f9483b51f210b3305c1994bb568c0387df4 Mon Sep 17 00:00:00 2001 From: Chengyin Liu Date: Tue, 25 Oct 2016 18:44:18 -0700 Subject: [PATCH] Better font family check on iOS Font names can be specified as something like `Helvetica-Bold`. This is specially common when using custom fonts. This fix makes sure those supported custom fonts are not accidentally removed. Fix #122 --- ios/Utils/RCTConvert+RNSVG.m | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ios/Utils/RCTConvert+RNSVG.m b/ios/Utils/RCTConvert+RNSVG.m index 0d841a69..6a4b2236 100644 --- a/ios/Utils/RCTConvert+RNSVG.m +++ b/ios/Utils/RCTConvert+RNSVG.m @@ -102,10 +102,23 @@ RCT_ENUM_CONVERTER(RNSVGVBMOS, (@{ NSDictionary *fontDict = dict[@"font"]; NSString *fontFamily = fontDict[@"fontFamily"]; - if (![[UIFont familyNames] containsObject:fontFamily]) { - fontFamily = nil; + BOOL fontFound = NO; + NSArray *supportedFontFamilyNames = [UIFont familyNames]; + + if ([supportedFontFamilyNames containsObject:fontFamily]) { + fontFound = YES; + } else { + for (NSString *fontFamilyName in supportedFontFamilyNames) { + if ([[UIFont fontNamesForFamilyName: fontFamilyName] containsObject:fontFamily]) { + fontFound = YES; + break; + } + } } + fontFamily = fontFound ? fontFamily : nil; + + CTFontRef font = (__bridge CTFontRef)[RCTFont updateFont:nil withFamily:fontFamily size:fontDict[@"fontSize"] weight:fontDict[@"fontWeight"] style:fontDict[@"fontStyle"] variant:nil scaleMultiplier:1.0]; if (!font) {