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

[RNMobile] Update Editor block inserter button styles and default text input placeholder/selection styles #52269

Merged
merged 16 commits into from
Jul 12, 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
46 changes: 24 additions & 22 deletions packages/block-editor/src/components/inserter/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,15 @@ const VOICE_OVER_ANNOUNCEMENT_DELAY = 1000;
const defaultRenderToggle = ( {
onToggle,
disabled,
style,
containerStyle,
iconStyle,
buttonStyle,
onLongPress,
useExpandedMode,
} ) => {
// The "expanded mode" refers to the editor's appearance when no blocks
// are currently selected. The "add block" button has a separate style
// for the "expanded mode", which are added via the below "expandedModeViewProps"
// and "expandedModeViewText" variables.
const expandedModeViewProps = useExpandedMode && {
icon: <Icon icon={ plus } style={ style } />,
customContainerStyles: containerStyle,
fixedRatio: false,
};
// are currently selected. The "add block" button has an style object
// for the expanded mode to correct the margins and padding:
// .inserter-menu__add-block-button--expanded
const expandedModeViewText = (
<Text style={ styles[ 'inserter-menu__add-block-button-text' ] }>
{ __( 'Add blocks' ) }
Expand All @@ -61,7 +56,7 @@ const defaultRenderToggle = ( {
'Add block',
'Generic label for block inserter button'
) }
icon={ <Icon icon={ plusCircleFilled } style={ style } /> }
icon={ <Icon icon={ plus } style={ iconStyle } /> }
onClick={ onToggle }
extraProps={ {
hint: __( 'Double tap to add a block' ),
Expand All @@ -71,7 +66,8 @@ const defaultRenderToggle = ( {
onLongPress,
} }
isDisabled={ disabled }
{ ...expandedModeViewProps }
customContainerStyles={ buttonStyle }
fixedRatio={ false }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By testing it a bit, I think we should add some hitSlop to this button, currently, this is not implemented but it should be easy to do and it will improve the UX of tapping on this button. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, updated.

>
{ useExpandedMode && expandedModeViewText }
</ToolbarButton>
Expand Down Expand Up @@ -254,18 +250,24 @@ export class Inserter extends Component {
if ( showSeparator && isOpen ) {
return <BlockInsertionPoint />;
}
const style = useExpandedMode
? styles[ 'inserter-menu__add-block-button-icon--expanded' ]
: getStylesFromColorScheme(
styles[ 'inserter-menu__add-block-button-icon' ],
styles[ 'inserter-menu__add-block-button-icon--dark' ]
);

const containerStyle = getStylesFromColorScheme(

const buttonColorScheme = getStylesFromColorScheme(
styles[ 'inserter-menu__add-block-button' ],
styles[ 'inserter-menu__add-block-button--dark' ]
);

const buttonStyle = {
...buttonColorScheme,
...( useExpandedMode
? styles[ 'inserter-menu__add-block-button--expanded' ]
: {} ),
};

const iconStyle = getStylesFromColorScheme(
styles[ 'inserter-menu__add-block-button-icon' ],
styles[ 'inserter-menu__add-block-button-icon--dark' ]
);

const onPress = () => {
this.setState(
{
Expand Down Expand Up @@ -301,8 +303,8 @@ export class Inserter extends Component {
onToggle: onPress,
isOpen,
disabled,
style,
containerStyle,
iconStyle,
buttonStyle,
onLongPress,
useExpandedMode,
} ) }
Expand Down
29 changes: 15 additions & 14 deletions packages/block-editor/src/components/inserter/style.native.scss
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
/** @format */

.inserter-menu__add-block-button-icon {
color: $blue-50;
.inserter-menu__add-block-button {
border-radius: 2px;
background-color: $black;
margin: 8px 8px 8px 10px;
padding: 2px 1px;
}

.inserter-menu__add-block-button-icon--dark {
color: $blue-30;
.inserter-menu__add-block-button--dark {
background-color: $white;
}

.inserter-menu__add-block-button-icon--expanded {
color: $white;
.inserter-menu__add-block-button--expanded {
border-radius: 2px;
margin: 10px;
padding: 2px 8px 2px 2px;
}

.inserter-menu__add-block-button {
border-radius: 22px;
background-color: $blue-50;
margin: 8px;
padding: 6px 16px 6px 12px;
.inserter-menu__add-block-button-icon {
color: $white;
}

.inserter-menu__add-block-button--dark {
background-color: $blue-30;
.inserter-menu__add-block-button-icon--dark {
color: $black;
}

.inserter-menu__add-block-button-text {
Expand Down
15 changes: 13 additions & 2 deletions packages/block-editor/src/components/rich-text/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import {
findTransform,
isUnmodifiedDefaultBlock,
} from '@wordpress/blocks';
import { useInstanceId, useMergeRefs } from '@wordpress/compose';
import {
useInstanceId,
useMergeRefs,
usePreferredColorSchemeStyle,
} from '@wordpress/compose';
import {
__experimentalRichText as RichText,
__unstableCreateElement,
Expand Down Expand Up @@ -203,6 +207,11 @@ function RichTextWrapper(
);
}

const defaultSelectionColor = usePreferredColorSchemeStyle(
'black',
'white'
);

const onSelectionChange = useCallback(
( selectionChangeStart, selectionChangeEnd ) => {
selectionChange(
Expand Down Expand Up @@ -619,7 +628,9 @@ function RichTextWrapper(
deleteEnter={ deleteEnter }
placeholderTextColor={ placeholderTextColor }
textAlign={ textAlign }
selectionColor={ selectionColor }
selectionColor={
selectionColor ? selectionColor : defaultSelectionColor
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@geriux I was trying to make updating the cursor/caret/selection color as simple and non-disruptive as possible. Since selectionColor is usually undefined for most components using RichText, I thought perhaps that adding a default selection color to the base RichText component would work best. Then, whenever selectionColor is passed as a prop, the selectionColor can still change, and will fallback to the default color if undefined. The objective was simplicity and reducing the chance of regressions, but I'm curious if you have any feedback here (especially before I update the failing snapshots where selectionColor was updated).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach sounds good to me, having a default value in case it is not set, just a few cases would set a custom selectionColor, for example, blocks like Button.

I've moved this logic to the RichText component though so that it would work for other cases like the PostTitle component. I also added a case to take into account block-based theme colors and color contrast detection, since I've encountered issues in light/dark mode using different block-based themes.

These changes were applied in 14d5695

tagsToEliminate={ tagsToEliminate }
disableEditingMenu={ disableEditingMenu }
fontSize={ fontSize }
Expand Down
2 changes: 1 addition & 1 deletion packages/rich-text/src/component/style.native.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}

.richTextPlaceholder {
color: $gray;
color: $gray-20;
}

.richTextPlaceholderDark {
Expand Down
Loading