|
9 | 9 |
|
10 | 10 | #import "RCTShadowText.h" |
11 | 11 |
|
| 12 | +#import "RCTAccessibilityManager.h" |
| 13 | +#import "RCTUIManager.h" |
| 14 | +#import "RCTBridge.h" |
12 | 15 | #import "RCTConvert.h" |
13 | 16 | #import "RCTLog.h" |
14 | 17 | #import "RCTShadowRawText.h" |
@@ -51,16 +54,31 @@ - (instancetype)init |
51 | 54 | _letterSpacing = NAN; |
52 | 55 | _isHighlighted = NO; |
53 | 56 | _textDecorationStyle = NSUnderlineStyleSingle; |
| 57 | + [[NSNotificationCenter defaultCenter] addObserver:self |
| 58 | + selector:@selector(contentSizeMultiplierDidChange:) |
| 59 | + name:RCTUIManagerWillUpdateViewsDueToContentSizeMultiplierChangeNotification |
| 60 | + object:nil]; |
54 | 61 | } |
55 | 62 | return self; |
56 | 63 | } |
57 | 64 |
|
| 65 | +- (void)dealloc |
| 66 | +{ |
| 67 | + [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 68 | +} |
| 69 | + |
58 | 70 | - (NSString *)description |
59 | 71 | { |
60 | 72 | NSString *superDescription = super.description; |
61 | 73 | return [[superDescription substringToIndex:superDescription.length - 1] stringByAppendingFormat:@"; text: %@>", [self attributedString].string]; |
62 | 74 | } |
63 | 75 |
|
| 76 | +- (void)contentSizeMultiplierDidChange:(NSNotification *)note |
| 77 | +{ |
| 78 | + [self dirtyLayout]; |
| 79 | + [self dirtyText]; |
| 80 | +} |
| 81 | + |
64 | 82 | - (NSDictionary *)processUpdatedProperties:(NSMutableSet *)applierBlocks |
65 | 83 | parentProperties:(NSDictionary *)parentProperties |
66 | 84 | { |
@@ -190,7 +208,9 @@ - (NSAttributedString *)_attributedStringWithFontFamily:(NSString *)fontFamily |
190 | 208 | [self _addAttribute:NSBackgroundColorAttributeName withValue:self.backgroundColor toAttributedString:attributedString]; |
191 | 209 | } |
192 | 210 |
|
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)]; |
194 | 214 | [self _addAttribute:NSFontAttributeName withValue:font toAttributedString:attributedString]; |
195 | 215 | [self _addAttribute:NSKernAttributeName withValue:letterSpacing toAttributedString:attributedString]; |
196 | 216 | [self _addAttribute:RCTReactTagAttributeName withValue:self.reactTag toAttributedString:attributedString]; |
@@ -247,8 +267,9 @@ - (void)_setParagraphStyleOnAttributedString:(NSMutableAttributedString *)attrib |
247 | 267 | NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; |
248 | 268 | paragraphStyle.alignment = _textAlign; |
249 | 269 | paragraphStyle.baseWritingDirection = _writingDirection; |
250 | | - paragraphStyle.minimumLineHeight = _lineHeight; |
251 | | - paragraphStyle.maximumLineHeight = _lineHeight; |
| 270 | + CGFloat lineHeight = round(_lineHeight * self.fontSizeMultiplier); |
| 271 | + paragraphStyle.minimumLineHeight = lineHeight; |
| 272 | + paragraphStyle.maximumLineHeight = lineHeight; |
252 | 273 | [attributedString addAttribute:NSParagraphStyleAttributeName |
253 | 274 | value:paragraphStyle |
254 | 275 | range:(NSRange){0, attributedString.length}]; |
@@ -321,4 +342,26 @@ - (void)set##setProp:(type)value; \ |
321 | 342 | RCT_TEXT_PROPERTY(TextDecorationStyle, _textDecorationStyle, NSUnderlineStyle); |
322 | 343 | RCT_TEXT_PROPERTY(WritingDirection, _writingDirection, NSWritingDirection) |
323 | 344 |
|
| 345 | +- (void)setAllowFontScaling:(BOOL)allowFontScaling |
| 346 | +{ |
| 347 | + _allowFontScaling = allowFontScaling; |
| 348 | + for (RCTShadowView *child in [self reactSubviews]) { |
| 349 | + if ([child isKindOfClass:[RCTShadowText class]]) { |
| 350 | + [(RCTShadowText *)child setAllowFontScaling:allowFontScaling]; |
| 351 | + } |
| 352 | + } |
| 353 | + [self dirtyText]; |
| 354 | +} |
| 355 | + |
| 356 | +- (void)setFontSizeMultiplier:(CGFloat)fontSizeMultiplier |
| 357 | +{ |
| 358 | + _fontSizeMultiplier = fontSizeMultiplier; |
| 359 | + for (RCTShadowView *child in [self reactSubviews]) { |
| 360 | + if ([child isKindOfClass:[RCTShadowText class]]) { |
| 361 | + [(RCTShadowText *)child setFontSizeMultiplier:fontSizeMultiplier]; |
| 362 | + } |
| 363 | + } |
| 364 | + [self dirtyText]; |
| 365 | +} |
| 366 | + |
324 | 367 | @end |
0 commit comments