From 3cb9c589c28aef5fe830c5d9055834d96d665c9d Mon Sep 17 00:00:00 2001 From: helele <297359127@qq.com> Date: Fri, 8 Jun 2018 10:42:04 +0800 Subject: [PATCH 1/4] Text BackgroundColor bug The background of the Text does not need to use NSBackgroundColorAttributeName. When the background color contains alpha, it will conflict with the UIView background color, cause a bug. --- Libraries/Text/RCTTextAttributes.h | 3 +-- Libraries/Text/RCTTextAttributes.m | 15 --------------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/Libraries/Text/RCTTextAttributes.h b/Libraries/Text/RCTTextAttributes.h index 7575bb17269f80..49afaf53e6a1ba 100644 --- a/Libraries/Text/RCTTextAttributes.h +++ b/Libraries/Text/RCTTextAttributes.h @@ -76,10 +76,9 @@ extern NSString *const RCTTextAttributesTagAttributeName; - (CGFloat)effectiveFontSizeMultiplier; /** - * Foreground and background colors with opacity and right defaults. + * Foreground colors with opacity and right defaults. */ - (UIColor *)effectiveForegroundColor; -- (UIColor *)effectiveBackgroundColor; /** * Text transformed per 'none', 'uppercase', 'lowercase', 'capitalize' diff --git a/Libraries/Text/RCTTextAttributes.m b/Libraries/Text/RCTTextAttributes.m index 4309138d00fe09..0824622b84e871 100644 --- a/Libraries/Text/RCTTextAttributes.m +++ b/Libraries/Text/RCTTextAttributes.m @@ -95,10 +95,6 @@ - (void)applyTextAttributes:(RCTTextAttributes *)textAttributes attributes[NSForegroundColorAttributeName] = effectiveForegroundColor; } - if (_backgroundColor || !isnan(_opacity)) { - attributes[NSBackgroundColorAttributeName] = self.effectiveBackgroundColor; - } - // Kerning if (!isnan(_letterSpacing)) { attributes[NSKernAttributeName] = @(_letterSpacing); @@ -205,17 +201,6 @@ - (UIColor *)effectiveForegroundColor return effectiveForegroundColor; } -- (UIColor *)effectiveBackgroundColor -{ - UIColor *effectiveBackgroundColor = _backgroundColor;// ?: [[UIColor whiteColor] colorWithAlphaComponent:0]; - - if (effectiveBackgroundColor && !isnan(_opacity)) { - effectiveBackgroundColor = [effectiveBackgroundColor colorWithAlphaComponent:CGColorGetAlpha(effectiveBackgroundColor.CGColor) * _opacity]; - } - - return effectiveBackgroundColor ?: [UIColor clearColor]; -} - - (NSString *)applyTextAttributesToText:(NSString *)text { switch (_textTransform) { From a711fa463e20553e2ca360d0a55ce2465526a1f1 Mon Sep 17 00:00:00 2001 From: helele <297359127@qq.com> Date: Fri, 8 Jun 2018 11:19:56 +0800 Subject: [PATCH 2/4] Text BackgroundColor bug The background of the Text does not need to use NSBackgroundColorAttributeName. When the background color contains alpha, it will conflict with the UIView background color, cause a bug. --- Libraries/Text/RCTTextAttributes.h | 3 ++- Libraries/Text/RCTTextAttributes.m | 13 ++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Libraries/Text/RCTTextAttributes.h b/Libraries/Text/RCTTextAttributes.h index 49afaf53e6a1ba..7575bb17269f80 100644 --- a/Libraries/Text/RCTTextAttributes.h +++ b/Libraries/Text/RCTTextAttributes.h @@ -76,9 +76,10 @@ extern NSString *const RCTTextAttributesTagAttributeName; - (CGFloat)effectiveFontSizeMultiplier; /** - * Foreground colors with opacity and right defaults. + * Foreground and background colors with opacity and right defaults. */ - (UIColor *)effectiveForegroundColor; +- (UIColor *)effectiveBackgroundColor; /** * Text transformed per 'none', 'uppercase', 'lowercase', 'capitalize' diff --git a/Libraries/Text/RCTTextAttributes.m b/Libraries/Text/RCTTextAttributes.m index 0824622b84e871..82b89da103ea60 100644 --- a/Libraries/Text/RCTTextAttributes.m +++ b/Libraries/Text/RCTTextAttributes.m @@ -88,7 +88,7 @@ - (void)applyTextAttributes:(RCTTextAttributes *)textAttributes attributes[NSFontAttributeName] = font; } - // Colors + // Color UIColor *effectiveForegroundColor = self.effectiveForegroundColor; if (_foregroundColor || !isnan(_opacity)) { @@ -201,6 +201,17 @@ - (UIColor *)effectiveForegroundColor return effectiveForegroundColor; } +- (UIColor *)effectiveBackgroundColor +{ + UIColor *effectiveBackgroundColor = _backgroundColor;// ?: [[UIColor whiteColor] colorWithAlphaComponent:0]; + + if (effectiveBackgroundColor && !isnan(_opacity)) { + effectiveBackgroundColor = [effectiveBackgroundColor colorWithAlphaComponent:CGColorGetAlpha(effectiveBackgroundColor.CGColor) * _opacity]; + } + + return effectiveBackgroundColor ?: [UIColor clearColor]; +} + - (NSString *)applyTextAttributesToText:(NSString *)text { switch (_textTransform) { From 7ac8655b2381197fd904c2b4df2c9afe50826afb Mon Sep 17 00:00:00 2001 From: helele <297359127@qq.com> Date: Fri, 8 Jun 2018 14:43:58 +0800 Subject: [PATCH 3/4] line height bug if text has lineHeight style, such as English Japanese Chinese cannot be vertically aligned. --- Libraries/Text/Text/RCTTextShadowView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libraries/Text/Text/RCTTextShadowView.m b/Libraries/Text/Text/RCTTextShadowView.m index 1266f8afd74dd9..cc0f709845b65d 100644 --- a/Libraries/Text/Text/RCTTextShadowView.m +++ b/Libraries/Text/Text/RCTTextShadowView.m @@ -148,7 +148,7 @@ - (void)postprocessAttributedText:(NSMutableAttributedString *)attributedText return; } - CGFloat baseLineOffset = maximumLineHeight / 2.0 - font.lineHeight / 2.0; + CGFloat baseLineOffset = maximumLineHeight / 2.0 - font.pointSize / 2.0; [attributedText addAttribute:NSBaselineOffsetAttributeName value:@(baseLineOffset) From e421ccfe7d8e5ee881dd381ce5815436a28df3e5 Mon Sep 17 00:00:00 2001 From: helele <297359127@qq.com> Date: Fri, 8 Jun 2018 15:00:32 +0800 Subject: [PATCH 4/4] Revert "line height bug" This reverts commit 7ac8655b2381197fd904c2b4df2c9afe50826afb. --- Libraries/Text/Text/RCTTextShadowView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libraries/Text/Text/RCTTextShadowView.m b/Libraries/Text/Text/RCTTextShadowView.m index cc0f709845b65d..1266f8afd74dd9 100644 --- a/Libraries/Text/Text/RCTTextShadowView.m +++ b/Libraries/Text/Text/RCTTextShadowView.m @@ -148,7 +148,7 @@ - (void)postprocessAttributedText:(NSMutableAttributedString *)attributedText return; } - CGFloat baseLineOffset = maximumLineHeight / 2.0 - font.pointSize / 2.0; + CGFloat baseLineOffset = maximumLineHeight / 2.0 - font.lineHeight / 2.0; [attributedText addAttribute:NSBaselineOffsetAttributeName value:@(baseLineOffset)