From 4cf971328b812842a4534ce2caea6262b36cd107 Mon Sep 17 00:00:00 2001 From: Tucker Connelly Date: Tue, 17 May 2016 10:30:58 -0400 Subject: [PATCH 1/4] Vertically center iOS text if lineHeight is set --- Libraries/Text/RCTShadowText.m | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Libraries/Text/RCTShadowText.m b/Libraries/Text/RCTShadowText.m index adf7be667d5520..4873821f9ea507 100644 --- a/Libraries/Text/RCTShadowText.m +++ b/Libraries/Text/RCTShadowText.m @@ -306,6 +306,11 @@ - (void)_setParagraphStyleOnAttributedString:(NSMutableAttributedString *)attrib CGFloat lineHeight = round(_lineHeight * fontSizeMultiplier); paragraphStyle.minimumLineHeight = lineHeight; paragraphStyle.maximumLineHeight = lineHeight; + // vertically center text + CGFloat fontSize = round(_fontSize * (_allowFontScaling && self.fontSizeMultiplier > 0.0 ? self.fontSizeMultiplier : 1.0)); + [attributedString addAttribute:NSBaselineOffsetAttributeName + value:[NSNumber numberWithFloat:lineHeight/2 - fontSize/2] + range:(NSRange){0, attributedString.length}]; [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:(NSRange){0, attributedString.length}]; From 77702c38e383a2ec8b9b3b76525c144494a8cb2d Mon Sep 17 00:00:00 2001 From: Tucker Connelly Date: Sun, 29 May 2016 16:31:54 -0400 Subject: [PATCH 2/4] Change baseline formatting for PR --- Libraries/Text/RCTShadowText.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libraries/Text/RCTShadowText.m b/Libraries/Text/RCTShadowText.m index 4873821f9ea507..e1e45761ad42b8 100644 --- a/Libraries/Text/RCTShadowText.m +++ b/Libraries/Text/RCTShadowText.m @@ -309,7 +309,7 @@ - (void)_setParagraphStyleOnAttributedString:(NSMutableAttributedString *)attrib // vertically center text CGFloat fontSize = round(_fontSize * (_allowFontScaling && self.fontSizeMultiplier > 0.0 ? self.fontSizeMultiplier : 1.0)); [attributedString addAttribute:NSBaselineOffsetAttributeName - value:[NSNumber numberWithFloat:lineHeight/2 - fontSize/2] + value:@(lineHeight/2 - fontSize/2) range:(NSRange){0, attributedString.length}]; [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle From df692d002e3fbea3a35219e1fcc94b9397a047ed Mon Sep 17 00:00:00 2001 From: Tucker Connelly Date: Sun, 29 May 2016 16:33:40 -0400 Subject: [PATCH 3/4] Handle unset fontSizes in baseline calculation --- Libraries/Text/RCTShadowText.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Libraries/Text/RCTShadowText.m b/Libraries/Text/RCTShadowText.m index e1e45761ad42b8..4d6b01c39b556a 100644 --- a/Libraries/Text/RCTShadowText.m +++ b/Libraries/Text/RCTShadowText.m @@ -307,7 +307,10 @@ - (void)_setParagraphStyleOnAttributedString:(NSMutableAttributedString *)attrib paragraphStyle.minimumLineHeight = lineHeight; paragraphStyle.maximumLineHeight = lineHeight; // vertically center text - CGFloat fontSize = round(_fontSize * (_allowFontScaling && self.fontSizeMultiplier > 0.0 ? self.fontSizeMultiplier : 1.0)); + + CGFloat fontSize = _fontSize && !isnan(_fontSize) ? _fontSize : UIFont.systemFontSize; + fontSize *= fontSizeMultiplier; + [attributedString addAttribute:NSBaselineOffsetAttributeName value:@(lineHeight/2 - fontSize/2) range:(NSRange){0, attributedString.length}]; From 0b509074f45e6a8aa50cfba57e2d274ae0786de1 Mon Sep 17 00:00:00 2001 From: Tucker Connelly Date: Sun, 29 May 2016 16:41:23 -0400 Subject: [PATCH 4/4] Put baseline comment on the right line --- Libraries/Text/RCTShadowText.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libraries/Text/RCTShadowText.m b/Libraries/Text/RCTShadowText.m index 4d6b01c39b556a..fe2a0657d9bd4d 100644 --- a/Libraries/Text/RCTShadowText.m +++ b/Libraries/Text/RCTShadowText.m @@ -306,8 +306,8 @@ - (void)_setParagraphStyleOnAttributedString:(NSMutableAttributedString *)attrib CGFloat lineHeight = round(_lineHeight * fontSizeMultiplier); paragraphStyle.minimumLineHeight = lineHeight; paragraphStyle.maximumLineHeight = lineHeight; - // vertically center text + // vertically center text CGFloat fontSize = _fontSize && !isnan(_fontSize) ? _fontSize : UIFont.systemFontSize; fontSize *= fontSizeMultiplier;