Vertically center iOS text if lineHeight is set
Summary: First PR!! This fixes https://github.com/facebook/react-native/issues/2991 :) Closes https://github.com/facebook/react-native/pull/7603 Differential Revision: D3417257 fbshipit-source-id: 074d56c1dfc0a9ba713e59c804286fd915589eeb
This commit is contained in:
parent
d43e0db81e
commit
33dfc9db92
|
@ -369,6 +369,14 @@ static css_dim_t RCTMeasure(void *context, float width, css_measure_mode_t width
|
||||||
}
|
}
|
||||||
paragraphStyle.minimumLineHeight = lineHeight;
|
paragraphStyle.minimumLineHeight = lineHeight;
|
||||||
paragraphStyle.maximumLineHeight = lineHeight;
|
paragraphStyle.maximumLineHeight = lineHeight;
|
||||||
|
|
||||||
|
// vertically center text
|
||||||
|
CGFloat fontSize = _fontSize && !isnan(_fontSize) ? _fontSize : UIFont.systemFontSize;
|
||||||
|
fontSize *= fontSizeMultiplier;
|
||||||
|
|
||||||
|
[attributedString addAttribute:NSBaselineOffsetAttributeName
|
||||||
|
value:@(lineHeight/2 - fontSize/2)
|
||||||
|
range:(NSRange){0, attributedString.length}];
|
||||||
[attributedString addAttribute:NSParagraphStyleAttributeName
|
[attributedString addAttribute:NSParagraphStyleAttributeName
|
||||||
value:paragraphStyle
|
value:paragraphStyle
|
||||||
range:(NSRange){0, attributedString.length}];
|
range:(NSRange){0, attributedString.length}];
|
||||||
|
|
Loading…
Reference in New Issue