From 67c36cf1373ce2e54fcf8192b5afcea5a06a4c7f Mon Sep 17 00:00:00 2001 From: Gerardo Date: Thu, 3 Feb 2022 08:51:50 +0100 Subject: [PATCH 1/2] Mobile - Rich Text - Validate link colors --- packages/rich-text/src/component/index.native.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/rich-text/src/component/index.native.js b/packages/rich-text/src/component/index.native.js index 150e46133723d..ff2e385596a5c 100644 --- a/packages/rich-text/src/component/index.native.js +++ b/packages/rich-text/src/component/index.native.js @@ -6,6 +6,7 @@ import { View, Platform, Dimensions } from 'react-native'; import { get, pickBy, debounce } from 'lodash'; import memize from 'memize'; +import { colord } from 'colord'; /** * WordPress dependencies @@ -1015,6 +1016,15 @@ export class RichText extends Component { return isBlockBasedTheme && tagsToMatch.test( tagName ); } + getLinkTextColor( defaultColor ) { + const { style } = this.props; + const customColor = style?.linkColor && colord( style.linkColor ); + + return customColor && customColor.isValid() + ? customColor.toHex() + : defaultColor; + } + render() { const { tagName, @@ -1051,6 +1061,9 @@ export class RichText extends Component { textDecorationColor: defaultTextDecorationColor, fontFamily: defaultFontFamily, } = getStylesFromColorScheme( styles.richText, styles.richTextDark ); + const textLinkColor = this.getLinkTextColor( + defaultTextDecorationColor + ); let selection = null; if ( this.needsSelectionUpdate ) { @@ -1146,8 +1159,7 @@ export class RichText extends Component { text: html, eventCount: this.lastEventCount, selection, - linkTextColor: - style?.linkColor || defaultTextDecorationColor, + linkTextColor: textLinkColor, tag: tagName, } } placeholder={ this.props.placeholder } From 6b4d8ff1c5bae95539fed8cd2651f511d37decde Mon Sep 17 00:00:00 2001 From: Gerardo Date: Thu, 3 Feb 2022 11:20:22 +0100 Subject: [PATCH 2/2] Mobile - Rich Text - Update naming to match prop --- packages/rich-text/src/component/index.native.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/rich-text/src/component/index.native.js b/packages/rich-text/src/component/index.native.js index ff2e385596a5c..43b6f6de6a2d8 100644 --- a/packages/rich-text/src/component/index.native.js +++ b/packages/rich-text/src/component/index.native.js @@ -1061,7 +1061,7 @@ export class RichText extends Component { textDecorationColor: defaultTextDecorationColor, fontFamily: defaultFontFamily, } = getStylesFromColorScheme( styles.richText, styles.richTextDark ); - const textLinkColor = this.getLinkTextColor( + const linkTextColor = this.getLinkTextColor( defaultTextDecorationColor ); @@ -1159,7 +1159,7 @@ export class RichText extends Component { text: html, eventCount: this.lastEventCount, selection, - linkTextColor: textLinkColor, + linkTextColor, tag: tagName, } } placeholder={ this.props.placeholder }