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 5 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
52 changes: 16 additions & 36 deletions packages/block-editor/src/components/inserter/index.native.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { AccessibilityInfo, Platform, Text } from 'react-native';
import { AccessibilityInfo, Platform } from 'react-native';

/**
* WordPress dependencies
Expand Down Expand Up @@ -35,33 +35,17 @@ 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,
};
const expandedModeViewText = (
<Text style={ styles[ 'inserter-menu__add-block-button-text' ] }>
{ __( 'Add blocks' ) }
</Text>
);

return (
<ToolbarButton
title={ _x(
'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,10 +55,9 @@ const defaultRenderToggle = ( {
onLongPress,
} }
isDisabled={ disabled }
{ ...expandedModeViewProps }
>
{ useExpandedMode && expandedModeViewText }
</ToolbarButton>
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.

/>
);
};

Expand Down Expand Up @@ -249,23 +232,21 @@ export class Inserter extends Component {
renderToggle = defaultRenderToggle,
getStylesFromColorScheme,
showSeparator,
useExpandedMode,
} = this.props;
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 buttonStyle = getStylesFromColorScheme(
styles[ 'inserter-menu__add-block-button' ],
styles[ 'inserter-menu__add-block-button--dark' ]
);

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,10 +282,9 @@ export class Inserter extends Component {
onToggle: onPress,
isOpen,
disabled,
style,
containerStyle,
iconStyle,
buttonStyle,
onLongPress,
useExpandedMode,
} ) }
<Picker
ref={ ( instance ) => ( this.picker = instance ) }
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ function HeaderToolbar( {
noContentSelected,
} ) {
const wasNoContentSelected = useRef( noContentSelected );
// eslint-disable-next-line no-unused-vars
const [ isInserterOpen, setIsInserterOpen ] = useState( false );
Copy link
Member Author

Choose a reason for hiding this comment

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

Although isInserterOpen and other references to the open inserter are no longer used in this file, isInserterOpen is still used in the media block insertion PR. Rather than remove all of the references here, // eslint-disable-next-line no-unused-vars is used. This line can be removed once merged.

Copy link
Member

Choose a reason for hiding this comment

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

I've removed this code in 3b4c5c2 👍


const containerStyle = getStylesFromColorScheme(
styles[ 'header-toolbar__container' ],
styles[ 'header-toolbar__container--dark' ]
);

const scrollViewRef = useRef( null );
const scrollToStart = () => {
// scrollview doesn't seem to automatically adjust to RTL on Android so, scroll to end when Android
Expand Down Expand Up @@ -93,27 +99,14 @@ function HeaderToolbar( {
[ noContentSelected ]
);

// Expanded mode should be preserved while the inserter is open.
// This way we prevent style updates during the opening transition.
const useExpandedMode = isInserterOpen
? wasNoContentSelected.current
: noContentSelected;

/* translators: accessibility text for the editor toolbar */
const toolbarAriaLabel = __( 'Document tools' );

return (
<View
testID={ toolbarAriaLabel }
accessibilityLabel={ toolbarAriaLabel }
style={ [
getStylesFromColorScheme(
styles[ 'header-toolbar__container' ],
styles[ 'header-toolbar__container--dark' ]
),
useExpandedMode &&
styles[ 'header-toolbar__container--expanded' ],
] }
style={ containerStyle }
>
<ScrollView
ref={ scrollViewRef }
Expand All @@ -128,7 +121,6 @@ function HeaderToolbar( {
>
<Inserter
disabled={ ! showInserter }
useExpandedMode={ useExpandedMode }
onToggle={ onToggleInserter }
/>
{ renderHistoryButtons() }
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