Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mobile - RichText - Update logic for the placeholder text color #54259

Merged
merged 5 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const hitSlop = { top: 22, bottom: 22, left: 22, right: 22 };
const noop = () => {};

export function DefaultBlockAppender( {
baseGlobalStyles,
isLocked,
isVisible,
onAppend,
Expand All @@ -34,6 +35,15 @@ export function DefaultBlockAppender( {
if ( isLocked || ! isVisible ) {
return null;
}
const blockGlobalStyles = baseGlobalStyles?.blocks?.[ 'core/paragraph' ];
const { fontSize, lineHeight } = blockGlobalStyles?.typography || {};

const textStyles = blockGlobalStyles?.typography
? {
...( fontSize && { fontSize } ),
...( lineHeight && { lineHeight } ),
}
: undefined;

const value =
typeof placeholder === 'string'
Expand All @@ -51,7 +61,12 @@ export function DefaultBlockAppender( {
{ showSeparator ? (
<BlockInsertionPoint />
) : (
<RichText placeholder={ value } onChange={ noop } />
<RichText
placeholder={ value }
onChange={ noop }
tagName="p"
style={ textStyles }
/>
) }
</View>
</Pressable>
Expand All @@ -60,16 +75,24 @@ export function DefaultBlockAppender( {

export default compose(
withSelect( ( select, ownProps ) => {
const { getBlockCount, getBlockName, isBlockValid, getTemplateLock } =
select( blockEditorStore );
const {
getBlockCount,
getBlockName,
getSettings,
isBlockValid,
getTemplateLock,
} = select( blockEditorStore );

const isEmpty = ! getBlockCount( ownProps.rootClientId );
const isLastBlockDefault =
getBlockName( ownProps.lastBlockClientId ) ===
getDefaultBlockName();
const isLastBlockValid = isBlockValid( ownProps.lastBlockClientId );
const globalStylesBaseStyles =
getSettings()?.__experimentalGlobalStylesBaseStyles;

return {
baseGlobalStyles: globalStylesBaseStyles,
isVisible: isEmpty || ! isLastBlockDefault || ! isLastBlockValid,
isLocked: !! getTemplateLock( ownProps.rootClientId ),
};
Expand Down
48 changes: 36 additions & 12 deletions packages/rich-text/src/component/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,41 @@ export class RichText extends Component {
: defaultColor;
}

getPlaceholderTextColor() {
const {
baseGlobalStyles,
getStylesFromColorScheme,
placeholderTextColor,
style,
} = this.props;

// Default placeholder text color.
const placeholderStyle = getStylesFromColorScheme(
styles.richTextPlaceholder,
styles.richTextPlaceholderDark
);
const { color: defaultPlaceholderTextColor } = placeholderStyle;
// Custom 63% opacity for theme and inherited colors.
const placeholderOpacity = 'A1';

// Determine inherited placeholder color if available.
const inheritPlaceholderColor = style?.placeholderColor
? `${ style.placeholderColor }${ placeholderOpacity }`
: undefined;

// If using block-based themes, derive the placeholder color from global styles.
const globalStylesPlaceholderColor = baseGlobalStyles?.color?.text
? `${ baseGlobalStyles.color.text }${ placeholderOpacity }`
: undefined;

return (
inheritPlaceholderColor ??
placeholderTextColor ??
globalStylesPlaceholderColor ??
defaultPlaceholderTextColor
);
}

render() {
const {
tagName,
Expand All @@ -1085,12 +1120,6 @@ export class RichText extends Component {
const editableProps = this.getEditableProps();
const blockUseDefaultFont = this.getBlockUseDefaultFont();

const placeholderStyle = getStylesFromColorScheme(
styles.richTextPlaceholder,
styles.richTextPlaceholderDark
);

const { color: defaultPlaceholderTextColor } = placeholderStyle;
const fontSize = currentFontSize;
const lineHeight = this.getLineHeight();

Expand Down Expand Up @@ -1218,12 +1247,7 @@ export class RichText extends Component {
tag: tagName,
} }
placeholder={ this.props.placeholder }
placeholderTextColor={
style?.placeholderColor ||
this.props.placeholderTextColor ||
( baseGlobalStyles && baseGlobalStyles?.color?.text ) ||
defaultPlaceholderTextColor
}
placeholderTextColor={ this.getPlaceholderTextColor() }
deleteEnter={ this.props.deleteEnter }
onChange={ this.onChangeFromAztec }
onFocus={ this.onFocus }
Expand Down
Loading