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
This commit is contained in:
Chengyin Liu
2016-10-25 18:44:18 -07:00
parent ded39cfc4a
commit 1a875f9483
+15 -2
View File
@@ -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) {