Skip to content

Commit

Permalink
Mobile - Rich Text - Validate link colors (#38474)
Browse files Browse the repository at this point in the history
* Mobile - Rich Text - Validate link colors

* Mobile - Rich Text - Update naming to match prop
  • Loading branch information
Gerardo Pacheco authored Feb 3, 2022
1 parent 4aa3187 commit 7ab78a2
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/rich-text/src/component/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1051,6 +1061,9 @@ export class RichText extends Component {
textDecorationColor: defaultTextDecorationColor,
fontFamily: defaultFontFamily,
} = getStylesFromColorScheme( styles.richText, styles.richTextDark );
const linkTextColor = this.getLinkTextColor(
defaultTextDecorationColor
);

let selection = null;
if ( this.needsSelectionUpdate ) {
Expand Down Expand Up @@ -1146,8 +1159,7 @@ export class RichText extends Component {
text: html,
eventCount: this.lastEventCount,
selection,
linkTextColor:
style?.linkColor || defaultTextDecorationColor,
linkTextColor,
tag: tagName,
} }
placeholder={ this.props.placeholder }
Expand Down

0 comments on commit 7ab78a2

Please sign in to comment.