99
1010#import " RCTShadowText.h"
1111
12+ #import " RCTAccessibilityManager.h"
13+ #import " RCTUIManager.h"
14+ #import " RCTBridge.h"
1215#import " RCTConvert.h"
1316#import " RCTLog.h"
1417#import " RCTShadowRawText.h"
@@ -51,16 +54,31 @@ - (instancetype)init
5154 _letterSpacing = NAN;
5255 _isHighlighted = NO ;
5356 _textDecorationStyle = NSUnderlineStyleSingle;
57+ [[NSNotificationCenter defaultCenter ] addObserver: self
58+ selector: @selector (contentSizeMultiplierDidChange: )
59+ name: RCTUIManagerWillUpdateViewsDueToContentSizeMultiplierChangeNotification
60+ object: nil ];
5461 }
5562 return self;
5663}
5764
65+ - (void )dealloc
66+ {
67+ [[NSNotificationCenter defaultCenter ] removeObserver: self ];
68+ }
69+
5870- (NSString *)description
5971{
6072 NSString *superDescription = super.description ;
6173 return [[superDescription substringToIndex: superDescription.length - 1 ] stringByAppendingFormat: @" ; text: %@ >" , [self attributedString ].string];
6274}
6375
76+ - (void )contentSizeMultiplierDidChange : (NSNotification *)note
77+ {
78+ [self dirtyLayout ];
79+ [self dirtyText ];
80+ }
81+
6482- (NSDictionary *)processUpdatedProperties : (NSMutableSet *)applierBlocks
6583 parentProperties : (NSDictionary *)parentProperties
6684{
@@ -190,7 +208,9 @@ - (NSAttributedString *)_attributedStringWithFontFamily:(NSString *)fontFamily
190208 [self _addAttribute: NSBackgroundColorAttributeName withValue: self .backgroundColor toAttributedString: attributedString];
191209 }
192210
193- UIFont *font = [RCTConvert UIFont: nil withFamily: fontFamily size: fontSize weight: fontWeight style: fontStyle];
211+ UIFont *font = [RCTConvert UIFont: nil withFamily: fontFamily
212+ size: fontSize weight: fontWeight style: fontStyle
213+ scaleMultiplier: (_allowFontScaling && _fontSizeMultiplier > 0.0 ? _fontSizeMultiplier : 1.0 )];
194214 [self _addAttribute: NSFontAttributeName withValue: font toAttributedString: attributedString];
195215 [self _addAttribute: NSKernAttributeName withValue: letterSpacing toAttributedString: attributedString];
196216 [self _addAttribute: RCTReactTagAttributeName withValue: self .reactTag toAttributedString: attributedString];
@@ -232,8 +252,9 @@ - (void)_setParagraphStyleOnAttributedString:(NSMutableAttributedString *)attrib
232252 [attributedString enumerateAttribute: NSParagraphStyleAttributeName inRange: NSMakeRange (0 , [attributedString length ]) options: 0 usingBlock: ^(id value, NSRange range, BOOL *stop) {
233253 if (value) {
234254 NSParagraphStyle *paragraphStyle = (NSParagraphStyle *)value;
235- if ([paragraphStyle maximumLineHeight ] > _lineHeight) {
236- self.lineHeight = [paragraphStyle maximumLineHeight ];
255+ CGFloat maximumLineHeight = round ([paragraphStyle maximumLineHeight ] / self.fontSizeMultiplier );
256+ if (maximumLineHeight > self.lineHeight ) {
257+ self.lineHeight = maximumLineHeight;
237258 }
238259 hasParagraphStyle = YES ;
239260 }
@@ -247,8 +268,9 @@ - (void)_setParagraphStyleOnAttributedString:(NSMutableAttributedString *)attrib
247268 NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc ] init ];
248269 paragraphStyle.alignment = _textAlign;
249270 paragraphStyle.baseWritingDirection = _writingDirection;
250- paragraphStyle.minimumLineHeight = _lineHeight;
251- paragraphStyle.maximumLineHeight = _lineHeight;
271+ CGFloat lineHeight = round (_lineHeight * self.fontSizeMultiplier );
272+ paragraphStyle.minimumLineHeight = lineHeight;
273+ paragraphStyle.maximumLineHeight = lineHeight;
252274 [attributedString addAttribute: NSParagraphStyleAttributeName
253275 value: paragraphStyle
254276 range: (NSRange ){0 , attributedString.length }];
@@ -321,4 +343,26 @@ - (void)set##setProp:(type)value; \
321343RCT_TEXT_PROPERTY (TextDecorationStyle, _textDecorationStyle, NSUnderlineStyle );
322344RCT_TEXT_PROPERTY (WritingDirection, _writingDirection, NSWritingDirection )
323345
346+ - (void )setAllowFontScaling:(BOOL )allowFontScaling
347+ {
348+ _allowFontScaling = allowFontScaling;
349+ for (RCTShadowView *child in [self reactSubviews ]) {
350+ if ([child isKindOfClass: [RCTShadowText class ]]) {
351+ [(RCTShadowText *)child setAllowFontScaling: allowFontScaling];
352+ }
353+ }
354+ [self dirtyText ];
355+ }
356+
357+ - (void )setFontSizeMultiplier : (CGFloat)fontSizeMultiplier
358+ {
359+ _fontSizeMultiplier = fontSizeMultiplier;
360+ for (RCTShadowView *child in [self reactSubviews ]) {
361+ if ([child isKindOfClass: [RCTShadowText class ]]) {
362+ [(RCTShadowText *)child setFontSizeMultiplier: fontSizeMultiplier];
363+ }
364+ }
365+ [self dirtyText ];
366+ }
367+
324368@end
0 commit comments