Skip to content

Commit 68d483e

Browse files
jacobp100Facebook Github Bot 8
authored andcommitted
Centre text in case where the distance between baselines is larger th…
Summary: …an the font size (per CSS spec) Extending upon work #7603 Closes #8851 ![screen shot 2016-08-04 at 14 49 21](https://cloud.githubusercontent.com/assets/7275322/17404165/bd67bc48-5a52-11e6-9ba1-5a8524f18867.png) ![screen shot 2016-08-04 at 14 49 24](https://cloud.githubusercontent.com/assets/7275322/17404167/be5f4044-5a52-11e6-9014-391349f9c5e1.png) Closes #9211 Differential Revision: D3706347 fbshipit-source-id: 0adfff8e8418b02f9b5d6671f5c89669e41abec3
1 parent c642136 commit 68d483e

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

52 Bytes
Loading

Libraries/Text/RCTShadowText.m

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,9 @@ - (NSAttributedString *)_attributedStringWithFontFamily:(NSString *)fontFamily
339339
[self _addAttribute:NSFontAttributeName withValue:font toAttributedString:attributedString];
340340
[self _addAttribute:NSKernAttributeName withValue:letterSpacing toAttributedString:attributedString];
341341
[self _addAttribute:RCTReactTagAttributeName withValue:self.reactTag toAttributedString:attributedString];
342-
[self _setParagraphStyleOnAttributedString:attributedString heightOfTallestSubview:heightOfTallestSubview];
342+
[self _setParagraphStyleOnAttributedString:attributedString
343+
fontLineHeight:font.lineHeight
344+
heightOfTallestSubview:heightOfTallestSubview];
343345

344346
// create a non-mutable attributedString for use by the Text system which avoids copies down the line
345347
_cachedAttributedString = [[NSAttributedString alloc] initWithAttributedString:attributedString];
@@ -362,6 +364,7 @@ - (void)_addAttribute:(NSString *)attribute withValue:(id)attributeValue toAttri
362364
* varying lineHeights, we simply take the max.
363365
*/
364366
- (void)_setParagraphStyleOnAttributedString:(NSMutableAttributedString *)attributedString
367+
fontLineHeight:(CGFloat)fontLineHeight
365368
heightOfTallestSubview:(CGFloat)heightOfTallestSubview
366369
{
367370
// check if we have lineHeight set on self
@@ -431,6 +434,12 @@ - (void)_setParagraphStyleOnAttributedString:(NSMutableAttributedString *)attrib
431434
[attributedString addAttribute:NSParagraphStyleAttributeName
432435
value:paragraphStyle
433436
range:(NSRange){0, attributedString.length}];
437+
438+
if (lineHeight > fontLineHeight) {
439+
[attributedString addAttribute:NSBaselineOffsetAttributeName
440+
value:@(lineHeight / 2 - fontLineHeight / 2)
441+
range:(NSRange){0, attributedString.length}];
442+
}
434443
}
435444

436445
// Text decoration

0 commit comments

Comments
 (0)