Disable font scaling when an explicit font handler is set

Reviewed By: sahrens

Differential Revision: D7003464

fbshipit-source-id: f36ff344c50a9c63af6c852138041c1c918259c8
This commit is contained in:
Mehdi Mulani 2018-02-16 12:08:59 -08:00 committed by Facebook Github Bot
parent cff522d283
commit f96dfb9468
3 changed files with 6 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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