From f96dfb946895c901c7823b06c26bfbbbd8b16862 Mon Sep 17 00:00:00 2001 From: Mehdi Mulani Date: Fri, 16 Feb 2018 12:08:59 -0800 Subject: [PATCH] Disable font scaling when an explicit font handler is set Reviewed By: sahrens Differential Revision: D7003464 fbshipit-source-id: f36ff344c50a9c63af6c852138041c1c918259c8 --- Libraries/Text/RCTTextAttributes.m | 2 +- React/Views/RCTFont.h | 1 + React/Views/RCTFont.mm | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Libraries/Text/RCTTextAttributes.m b/Libraries/Text/RCTTextAttributes.m index 26d63bdda8c..9b1ba122196 100644 --- a/Libraries/Text/RCTTextAttributes.m +++ b/Libraries/Text/RCTTextAttributes.m @@ -190,7 +190,7 @@ NSString *const RCTTextAttributesTagAttributeName = @"RCTTextAttributesTagAttrib - (CGFloat)effectiveFontSizeMultiplier { - return _allowFontScaling && !isnan(_fontSizeMultiplier) ? _fontSizeMultiplier : 1.0; + return !RCTHasFontHandlerSet() && _allowFontScaling && !isnan(_fontSizeMultiplier) ? _fontSizeMultiplier : 1.0; } - (UIColor *)effectiveForegroundColor diff --git a/React/Views/RCTFont.h b/React/Views/RCTFont.h index ba34e8f3462..711721d2a71 100644 --- a/React/Views/RCTFont.h +++ b/React/Views/RCTFont.h @@ -20,6 +20,7 @@ typedef UIFont *(^RCTFontHandler)(CGFloat fontSize, NSString *fontWeightDescript * "semibold", "extrabold", "bold", "heavy", or "black". */ RCT_EXTERN void RCTSetDefaultFontHandler(RCTFontHandler handler); +RCT_EXTERN BOOL RCTHasFontHandlerSet(); @interface RCTFont : NSObject diff --git a/React/Views/RCTFont.mm b/React/Views/RCTFont.mm index 37595dd3fbf..dc3877cb352 100644 --- a/React/Views/RCTFont.mm +++ b/React/Views/RCTFont.mm @@ -103,6 +103,10 @@ void RCTSetDefaultFontHandler(RCTFontHandler handler) { defaultFontHandler = handler; } +BOOL RCTHasFontHandlerSet() { + return defaultFontHandler != nil; +} + // We pass a string description of the font weight to the defaultFontHandler because UIFontWeight // is not defined pre-iOS 8.2. // Furthermore, UIFontWeight's are lossy floats, so we must use an inexact compare to figure out