Centre text in case where the distance between baselines is larger th…
Summary: …an the font size (per CSS spec) Extending upon work https://github.com/facebook/react-native/pull/7603 Closes https://github.com/facebook/react-native/pull/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 https://github.com/facebook/react-native/pull/9211 Differential Revision: D3706347 fbshipit-source-id: 0adfff8e8418b02f9b5d6671f5c89669e41abec3
This commit is contained in:
parent
c64213653e
commit
68d483e041
Binary file not shown.
Before Width: | Height: | Size: 364 KiB After Width: | Height: | Size: 365 KiB |
|
@ -339,7 +339,9 @@ static CSSSize RCTMeasure(void *context, float width, CSSMeasureMode widthMode,
|
|||
[self _addAttribute:NSFontAttributeName withValue:font toAttributedString:attributedString];
|
||||
[self _addAttribute:NSKernAttributeName withValue:letterSpacing toAttributedString:attributedString];
|
||||
[self _addAttribute:RCTReactTagAttributeName withValue:self.reactTag toAttributedString:attributedString];
|
||||
[self _setParagraphStyleOnAttributedString:attributedString heightOfTallestSubview:heightOfTallestSubview];
|
||||
[self _setParagraphStyleOnAttributedString:attributedString
|
||||
fontLineHeight:font.lineHeight
|
||||
heightOfTallestSubview:heightOfTallestSubview];
|
||||
|
||||
// create a non-mutable attributedString for use by the Text system which avoids copies down the line
|
||||
_cachedAttributedString = [[NSAttributedString alloc] initWithAttributedString:attributedString];
|
||||
|
@ -362,6 +364,7 @@ static CSSSize RCTMeasure(void *context, float width, CSSMeasureMode widthMode,
|
|||
* varying lineHeights, we simply take the max.
|
||||
*/
|
||||
- (void)_setParagraphStyleOnAttributedString:(NSMutableAttributedString *)attributedString
|
||||
fontLineHeight:(CGFloat)fontLineHeight
|
||||
heightOfTallestSubview:(CGFloat)heightOfTallestSubview
|
||||
{
|
||||
// check if we have lineHeight set on self
|
||||
|
@ -431,6 +434,12 @@ static CSSSize RCTMeasure(void *context, float width, CSSMeasureMode widthMode,
|
|||
[attributedString addAttribute:NSParagraphStyleAttributeName
|
||||
value:paragraphStyle
|
||||
range:(NSRange){0, attributedString.length}];
|
||||
|
||||
if (lineHeight > fontLineHeight) {
|
||||
[attributedString addAttribute:NSBaselineOffsetAttributeName
|
||||
value:@(lineHeight / 2 - fontLineHeight / 2)
|
||||
range:(NSRange){0, attributedString.length}];
|
||||
}
|
||||
}
|
||||
|
||||
// Text decoration
|
||||
|
|
Loading…
Reference in New Issue