From 38c7d9bf1bd1c7afd46df46bc7e4d46d925f2b9a Mon Sep 17 00:00:00 2001 From: BingBing Date: Mon, 11 Jun 2018 18:31:32 +0800 Subject: [PATCH 1/3] iOS: modify 'lineHeight' property behavior to fix the issue #19193 --- Libraries/Text/Text/RCTTextShadowView.m | 45 ++++++++++++++----------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/Libraries/Text/Text/RCTTextShadowView.m b/Libraries/Text/Text/RCTTextShadowView.m index 1266f8afd74..40ea4c445f7 100644 --- a/Libraries/Text/Text/RCTTextShadowView.m +++ b/Libraries/Text/Text/RCTTextShadowView.m @@ -133,30 +133,37 @@ - (void)postprocessAttributedText:(NSMutableAttributedString *)attributedText return; } - [attributedText beginEditing]; - + __block CGFloat maximumFontLineHeight = 0; + [attributedText enumerateAttribute:NSFontAttributeName inRange:NSMakeRange(0, attributedText.length) options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired usingBlock: - ^(UIFont *font, NSRange range, __unused BOOL *stop) { - if (!font) { - return; - } - - if (maximumLineHeight <= font.lineHeight) { - return; - } - - CGFloat baseLineOffset = maximumLineHeight / 2.0 - font.lineHeight / 2.0; - - [attributedText addAttribute:NSBaselineOffsetAttributeName - value:@(baseLineOffset) - range:range]; + ^(UIFont *font, NSRange range, __unused BOOL *stop) { + if (!font) { + return; } - ]; - - [attributedText endEditing]; + + if (maximumFontLineHeight <= font.lineHeight) { + maximumFontLineHeight = font.lineHeight; + } + + } + ]; + + if (maximumLineHeight < maximumFontLineHeight) { + return; + } + + [attributedText beginEditing]; + + CGFloat baseLineOffset = maximumLineHeight / 2.0 - maximumFontLineHeight / 2.0; + + [attributedText addAttribute:NSBaselineOffsetAttributeName + value:@(baseLineOffset) + range:NSMakeRange(0, attributedText.length)]; + + [attributedText endEditing]; } - (NSAttributedString *)attributedTextWithMeasuredAttachmentsThatFitSize:(CGSize)size From 48e0ef1841d850a96e764b5467e322cd3e61a810 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Sat, 29 Sep 2018 19:44:55 -0700 Subject: [PATCH 2/3] Update RCTTextShadowView.m nits --- Libraries/Text/Text/RCTTextShadowView.m | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/Libraries/Text/Text/RCTTextShadowView.m b/Libraries/Text/Text/RCTTextShadowView.m index 40ea4c445f7..1f5f7e35cf9 100644 --- a/Libraries/Text/Text/RCTTextShadowView.m +++ b/Libraries/Text/Text/RCTTextShadowView.m @@ -139,31 +139,26 @@ - (void)postprocessAttributedText:(NSMutableAttributedString *)attributedText inRange:NSMakeRange(0, attributedText.length) options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired usingBlock: - ^(UIFont *font, NSRange range, __unused BOOL *stop) { - if (!font) { - return; - } - - if (maximumFontLineHeight <= font.lineHeight) { - maximumFontLineHeight = font.lineHeight; - } + ^(UIFont *font, NSRange range, __unused BOOL *stop) { + if (!font) { + return; + } - } + if (maximumFontLineHeight <= font.lineHeight) { + maximumFontLineHeight = font.lineHeight; + } + } ]; if (maximumLineHeight < maximumFontLineHeight) { return; } - - [attributedText beginEditing]; - + CGFloat baseLineOffset = maximumLineHeight / 2.0 - maximumFontLineHeight / 2.0; [attributedText addAttribute:NSBaselineOffsetAttributeName value:@(baseLineOffset) range:NSMakeRange(0, attributedText.length)]; - - [attributedText endEditing]; } - (NSAttributedString *)attributedTextWithMeasuredAttachmentsThatFitSize:(CGSize)size From b4a177d2177cdfb177af6b5a8c1a12325449c6ba Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Sat, 29 Sep 2018 19:46:54 -0700 Subject: [PATCH 3/3] Update RCTTextShadowView.m other nits --- Libraries/Text/Text/RCTTextShadowView.m | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Libraries/Text/Text/RCTTextShadowView.m b/Libraries/Text/Text/RCTTextShadowView.m index 1f5f7e35cf9..9d0c6be0898 100644 --- a/Libraries/Text/Text/RCTTextShadowView.m +++ b/Libraries/Text/Text/RCTTextShadowView.m @@ -134,7 +134,7 @@ - (void)postprocessAttributedText:(NSMutableAttributedString *)attributedText } __block CGFloat maximumFontLineHeight = 0; - + [attributedText enumerateAttribute:NSFontAttributeName inRange:NSMakeRange(0, attributedText.length) options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired @@ -143,19 +143,19 @@ - (void)postprocessAttributedText:(NSMutableAttributedString *)attributedText if (!font) { return; } - + if (maximumFontLineHeight <= font.lineHeight) { maximumFontLineHeight = font.lineHeight; } } ]; - + if (maximumLineHeight < maximumFontLineHeight) { return; } - + CGFloat baseLineOffset = maximumLineHeight / 2.0 - maximumFontLineHeight / 2.0; - + [attributedText addAttribute:NSBaselineOffsetAttributeName value:@(baseLineOffset) range:NSMakeRange(0, attributedText.length)];