diff --git a/React/Base/RCTConvert.h b/React/Base/RCTConvert.h index 71bf7b302..2412f715b 100644 --- a/React/Base/RCTConvert.h +++ b/React/Base/RCTConvert.h @@ -76,6 +76,7 @@ + (UIImage *)UIImage:(id)json; + (CGImageRef)CGImage:(id)json; ++ (UIFont *)UIFont:(id)json; + (UIFont *)UIFont:(UIFont *)font withSize:(id)json; + (UIFont *)UIFont:(UIFont *)font withWeight:(id)json; + (UIFont *)UIFont:(UIFont *)font withStyle:(id)json; diff --git a/React/Base/RCTConvert.m b/React/Base/RCTConvert.m index 9c27b95d9..2d0606b6f 100644 --- a/React/Base/RCTConvert.m +++ b/React/Base/RCTConvert.m @@ -679,6 +679,16 @@ static BOOL RCTFontIsCondensed(UIFont *font) return (symbolicTraits & UIFontDescriptorTraitCondensed) != 0; } ++ (UIFont *)UIFont:(id)json +{ + json = [self NSDictionary:json]; + return [self UIFont:nil + withFamily:json[@"fontFamily"] + size:json[@"fontSize"] + weight:json[@"fontWeight"] + style:json[@"fontStyle"]]; +} + + (UIFont *)UIFont:(UIFont *)font withSize:(id)json { return [self UIFont:font withFamily:nil size:json weight:nil style:nil]; @@ -728,11 +738,6 @@ static BOOL RCTFontIsCondensed(UIFont *font) // Get font family familyName = [self NSString:family] ?: familyName; - // Get font style - if (style) { - isItalic = [self RCTFontStyle:style]; - } - // Gracefully handle being given a font name rather than font family, for // example: "Helvetica Light Oblique" rather than just "Helvetica". if ([UIFont fontNamesForFamilyName:familyName].count == 0) { @@ -751,6 +756,11 @@ static BOOL RCTFontIsCondensed(UIFont *font) } } + // Get font style + if (style) { + isItalic = [self RCTFontStyle:style]; + } + // Get font weight if (weight) { fontWeight = [self RCTFontWeight:weight]; @@ -758,13 +768,7 @@ static BOOL RCTFontIsCondensed(UIFont *font) // Get the closest font that matches the given weight for the fontFamily UIFont *bestMatch = [UIFont fontWithName:font.fontName size: fontSize]; - CGFloat closestWeight; - - if (font && [font.familyName isEqualToString: familyName]) { - closestWeight = RCTWeightOfFont(font); - } else { - closestWeight = INFINITY; - } + CGFloat closestWeight = INFINITY; for (NSString *name in [UIFont fontNamesForFamilyName:familyName]) { UIFont *match = [UIFont fontWithName:name size:fontSize]; diff --git a/React/Base/RCTDevMenu.m b/React/Base/RCTDevMenu.m index d2e4b7416..cf5c6635a 100644 --- a/React/Base/RCTDevMenu.m +++ b/React/Base/RCTDevMenu.m @@ -66,9 +66,7 @@ RCT_EXPORT_MODULE() // We're swizzling here because it's poor form to override methods in a category, // however UIWindow doesn't actually implement motionEnded:withEvent:, so there's // no need to call the original implementation. -#if RCT_DEV RCTSwapInstanceMethods([UIWindow class], @selector(motionEnded:withEvent:), @selector(RCT_motionEnded:withEvent:)); -#endif } - (instancetype)init