Skip to content

Commit f96dfb9

Browse files
Mehdi Mulanifacebook-github-bot
Mehdi Mulani
authored andcommitted
Disable font scaling when an explicit font handler is set
Reviewed By: sahrens Differential Revision: D7003464 fbshipit-source-id: f36ff344c50a9c63af6c852138041c1c918259c8
1 parent cff522d commit f96dfb9

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

Libraries/Text/RCTTextAttributes.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ - (UIFont *)effectiveFont
190190

191191
- (CGFloat)effectiveFontSizeMultiplier
192192
{
193-
return _allowFontScaling && !isnan(_fontSizeMultiplier) ? _fontSizeMultiplier : 1.0;
193+
return !RCTHasFontHandlerSet() && _allowFontScaling && !isnan(_fontSizeMultiplier) ? _fontSizeMultiplier : 1.0;
194194
}
195195

196196
- (UIColor *)effectiveForegroundColor

React/Views/RCTFont.h

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ typedef UIFont *(^RCTFontHandler)(CGFloat fontSize, NSString *fontWeightDescript
2020
* "semibold", "extrabold", "bold", "heavy", or "black".
2121
*/
2222
RCT_EXTERN void RCTSetDefaultFontHandler(RCTFontHandler handler);
23+
RCT_EXTERN BOOL RCTHasFontHandlerSet();
2324

2425
@interface RCTFont : NSObject
2526

React/Views/RCTFont.mm

+4
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ void RCTSetDefaultFontHandler(RCTFontHandler handler) {
103103
defaultFontHandler = handler;
104104
}
105105

106+
BOOL RCTHasFontHandlerSet() {
107+
return defaultFontHandler != nil;
108+
}
109+
106110
// We pass a string description of the font weight to the defaultFontHandler because UIFontWeight
107111
// is not defined pre-iOS 8.2.
108112
// Furthermore, UIFontWeight's are lossy floats, so we must use an inexact compare to figure out

0 commit comments

Comments
 (0)