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 "add block" button style in default editor view #39726

Merged
merged 45 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
2b3c19d
Update CHANGELOG
Mar 24, 2022
37960ce
Add 'add content' text
Mar 24, 2022
5ad815a
Add 'isDefaultView' check
Mar 24, 2022
556ac19
Rename CSS selectors to follow BEM methodology
Mar 24, 2022
53db20c
[WIP] Implement styles using 'isDefaultView' check
Mar 24, 2022
392832f
Separate 'defaultViewProps' for readability
Mar 25, 2022
b0693a7
Improvement to CSS code quality
Mar 29, 2022
8197083
Separate 'defaultViewText' into its own variable
Mar 29, 2022
46c31dd
Update CHANGELOG
Mar 29, 2022
03aa6ae
Merge branch 'trunk' into rnmobile/update/default-block-inserter-button
Mar 29, 2022
532c437
Remove redundant code causing unit test failure
Mar 29, 2022
b7ac622
Add styling for dark mode
Mar 29, 2022
d699e78
Merge branch 'trunk' into rnmobile/update/default-block-inserter-button
Mar 29, 2022
38df61c
Vertically align text within button
Mar 31, 2022
4af6403
Merge branch 'trunk' into rnmobile/update/default-block-inserter-button
Mar 31, 2022
005e6c7
Update text for clarity
Mar 31, 2022
4b5aa48
Assign larger height to toolbar in default view
Apr 6, 2022
19e5eb5
Hide new default view style when title's selected
Apr 6, 2022
ede9c16
Merge branch 'trunk' into rnmobile/update/default-block-inserter-button
Apr 6, 2022
0212fbf
Apply CSS for default toolbar
Apr 6, 2022
c31c897
Tweaks to button's styling
Apr 6, 2022
d8684a2
Update text in expanded button
Apr 7, 2022
0039c10
Set icon size to 24 (the default)
Apr 7, 2022
7769cac
Update height of editor's default toolbar
Apr 7, 2022
4a2ed4a
Refine expanded button's padding
Apr 7, 2022
c459a7b
Update button's background colour in light mode
Apr 7, 2022
d2822fe
Prevent expanded button displaying in some cases
Apr 7, 2022
82eeb5f
Merge branch 'trunk' into rnmobile/update/default-block-inserter-button
Apr 7, 2022
7d3399f
Revert "false fix"
Apr 8, 2022
fd73fa6
Turn 'isDefaultView' into 'global' editor setting
Apr 10, 2022
db5d32e
Prevent unwanted 'flash' of 'expanded' button
Apr 10, 2022
a35a8e5
Tweak code comment for clarity
Apr 10, 2022
3715ee6
Merge branch 'trunk' into rnmobile/update/default-block-inserter-button
Apr 10, 2022
ac5607e
Remove redundant code causing test failures
Apr 10, 2022
95cda71
Revert "Remove redundant code causing test failures"
Apr 10, 2022
24d9294
Revert "Turn 'isDefaultView' into 'global' editor setting"
fluiddot Apr 12, 2022
adf4173
Revert "Prevent unwanted 'flash' of 'expanded' button"
fluiddot Apr 12, 2022
bc9b4ea
Preserve isDefaultView value while inserter is open
fluiddot Apr 12, 2022
86fada7
Rename isInserterOpen state value
fluiddot Apr 12, 2022
28e772b
Apply BEM naming in header toolbar styles
fluiddot Apr 12, 2022
ee54130
Rename default view to expanded mode
fluiddot Apr 12, 2022
ee12890
Use hasSelectedBlock selector
fluiddot Apr 12, 2022
fc2403f
Fix header toolbar height in layout component
fluiddot Apr 12, 2022
4106e33
Add style mock
fluiddot Apr 12, 2022
1820356
Merge branch 'trunk' into rnmobile/update/default-block-inserter-button
fluiddot Apr 13, 2022
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
1 change: 1 addition & 0 deletions packages/base-styles/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ $block-bg-padding--h: 2.375em;

// Dimensions.
$mobile-header-toolbar-height: 44px;
$mobile-header-toolbar-expanded-height: 52px;
$mobile-floating-toolbar-height: 44px;
$mobile-floating-toolbar-margin: 8px;
$mobile-color-swatch: 48px;
Expand Down
85 changes: 60 additions & 25 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 } from 'react-native';
import { AccessibilityInfo, Platform, Text } from 'react-native';
import { delay } from 'lodash';

/**
Expand All @@ -15,6 +15,7 @@ import { compose, withPreferredColorScheme } from '@wordpress/compose';
import { isUnmodifiedDefaultBlock } from '@wordpress/blocks';
import {
Icon,
plus,
plusCircle,
plusCircleFilled,
insertAfter,
Expand All @@ -32,27 +33,51 @@ import { store as blockEditorStore } from '../../store';

const VOICE_OVER_ANNOUNCEMENT_DELAY = 1000;

const defaultRenderToggle = ( { onToggle, disabled, style, onLongPress } ) => (
<ToolbarButton
title={ _x( 'Add block', 'Generic label for block inserter button' ) }
icon={
<Icon
icon={ plusCircleFilled }
style={ style }
color={ style.color }
/>
}
onClick={ onToggle }
extraProps={ {
hint: __( 'Double tap to add a block' ),
// testID is present to disambiguate this element for native UI tests. It's not
// usually required for components. See: https://git.io/JeQ7G.
testID: 'add-block-button',
onLongPress,
} }
isDisabled={ disabled }
/>
);
const defaultRenderToggle = ( {
onToggle,
disabled,
style,
containerStyle,
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 } /> }
onClick={ onToggle }
extraProps={ {
hint: __( 'Double tap to add a block' ),
// testID is present to disambiguate this element for native UI tests. It's not
// usually required for components. See: https://git.io/JeQ7G.
testID: 'add-block-button',
onLongPress,
} }
isDisabled={ disabled }
{ ...expandedModeViewProps }
>
{ useExpandedMode && expandedModeViewText }
</ToolbarButton>
);
};

export class Inserter extends Component {
constructor() {
Expand Down Expand Up @@ -219,13 +244,21 @@ export class Inserter extends Component {
renderToggle = defaultRenderToggle,
getStylesFromColorScheme,
showSeparator,
useExpandedMode,
} = this.props;
if ( showSeparator && isOpen ) {
return <BlockInsertionPoint />;
}
const style = getStylesFromColorScheme(
styles.addBlockButton,
styles.addBlockButtonDark
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(
styles[ 'inserter-menu__add-block-button' ],
styles[ 'inserter-menu__add-block-button--dark' ]
);

const onPress = () => {
Expand Down Expand Up @@ -265,7 +298,9 @@ export class Inserter extends Component {
isOpen,
disabled,
style,
containerStyle,
onLongPress,
useExpandedMode,
} ) }
<Picker
ref={ ( instance ) => ( this.picker = instance ) }
Expand Down
27 changes: 24 additions & 3 deletions packages/block-editor/src/components/inserter/style.native.scss
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
/** @format */

.addBlockButton {
color: $blue-wordpress;
.inserter-menu__add-block-button-icon {
color: $blue-50;
}

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

.inserter-menu__add-block-button-icon--expanded {
color: $white;
}

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

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

.inserter-menu__add-block-button-text {
color: $white;
font-weight: 500;
align-self: center;
}

.inserter-menu__list-wrapper {
flex: 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Platform, ScrollView, View } from 'react-native';
/**
* WordPress dependencies
*/
import { useRef } from '@wordpress/element';
import { useCallback, useRef, useState } from '@wordpress/element';
import { compose, withPreferredColorScheme } from '@wordpress/compose';
import { withSelect, withDispatch } from '@wordpress/data';
import { withViewportMatch } from '@wordpress/viewport';
Expand Down Expand Up @@ -40,7 +40,11 @@ function HeaderToolbar( {
getStylesFromColorScheme,
onHideKeyboard,
isRTL,
noContentSelected,
} ) {
const wasNoContentSelected = useRef( noContentSelected );
const [ isInserterOpen, setIsInserterOpen ] = useState( false );

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 @@ -79,12 +83,32 @@ function HeaderToolbar( {
return isRTL ? buttons.reverse() : buttons;
};

const onToggleInserter = useCallback(
( isOpen ) => {
if ( isOpen ) {
wasNoContentSelected.current = noContentSelected;
}
setIsInserterOpen( isOpen );
},
[ 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;

return (
<View
style={ getStylesFromColorScheme(
styles.container,
styles.containerDark
) }
style={ [
getStylesFromColorScheme(
styles[ 'header-toolbar__container' ],
styles[ 'header-toolbar__container--dark' ]
),
useExpandedMode &&
styles[ 'header-toolbar__container--expanded' ],
] }
>
<ScrollView
ref={ scrollViewRef }
Expand All @@ -93,14 +117,24 @@ function HeaderToolbar( {
showsHorizontalScrollIndicator={ false }
keyboardShouldPersistTaps="always"
alwaysBounceHorizontal={ false }
contentContainerStyle={ styles.scrollableContent }
contentContainerStyle={
styles[ 'header-toolbar__scrollable-content' ]
}
>
<Inserter disabled={ ! showInserter } />
<Inserter
disabled={ ! showInserter }
useExpandedMode={ useExpandedMode }
onToggle={ onToggleInserter }
/>
{ renderHistoryButtons() }
<BlockToolbar />
</ScrollView>
{ showKeyboardHideButton && (
<ToolbarGroup passedStyle={ styles.keyboardHideContainer }>
<ToolbarGroup
passedStyle={
styles[ 'header-toolbar__keyboard-hide-container' ]
}
>
<ToolbarButton
title={ __( 'Hide keyboard' ) }
icon={ keyboardClose }
Expand All @@ -121,8 +155,13 @@ export default compose( [
getBlockRootClientId,
getBlockSelectionEnd,
hasInserterItems,
hasSelectedBlock,
} = select( blockEditorStore );
const { getEditorSettings } = select( editorStore );
const { getEditorSettings, isPostTitleSelected } = select(
editorStore
);
const isAnyBlockSelected = hasSelectedBlock();
const isTitleSelected = isPostTitleSelected();
return {
hasRedo: select( editorStore ).hasEditorRedo(),
hasUndo: select( editorStore ).hasEditorUndo(),
Expand All @@ -136,6 +175,7 @@ export default compose( [
isTextModeEnabled:
select( editPostStore ).getEditorMode() === 'text',
isRTL: select( blockEditorStore ).getSettings().isRTL,
noContentSelected: ! isAnyBlockSelected && ! isTitleSelected,
};
} ),
withDispatch( ( dispatch ) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@

.container {
.header-toolbar__container {
height: $mobile-header-toolbar-height;
flex-direction: row;
background-color: $app-background;
border-top-color: #e9eff3;
border-top-width: 1px;
}

.containerDark {
.header-toolbar__container--dark {
background-color: $app-background-dark-alt;
border-top-color: $background-dark-elevated;
}

.scrollableContent {
.header-toolbar__container--expanded {
height: $mobile-header-toolbar-expanded-height;
}

.header-toolbar__scrollable-content {
flex-grow: 1; // Fixes RTL issue on Android.
}

.keyboardHideContainer {
.header-toolbar__keyboard-hide-container {
padding-right: 0;
padding-left: 0;
padding-top: 4px;
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-post/src/components/layout/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class Layout extends Component {
// Add a margin view at the bottom for the header.
const marginBottom =
Platform.OS === 'android' && ! isHtmlView
? headerToolbarStyles.container.height
? headerToolbarStyles[ 'header-toolbar__container' ].height
Copy link
Contributor

Choose a reason for hiding this comment

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

This value takes the default height of the header toolbar, so it doesn't take into account the case when the toolbar is displayed in the expanded mode. As far as I tested, I didn't identify any visual issue regarding this logic, so looks safe to only use that value.

In the future, it would be great to update this calculation, and instead of accessing the height from the styles, retrieve it from the onLayout event.

: 0;

const toolbarKeyboardAvoidingViewStyle = {
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ For each user feature we should also add a importance categorization label to i

## Unreleased

- [**] Update "add block" button's style in default editor view. [#39726]
- [*] Remove banner error notification on upload failure [#39694]

## 1.73.1
Expand Down
3 changes: 3 additions & 0 deletions test/native/__mocks__/styleMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,7 @@ module.exports = {
addMediaButton: {
color: 'white',
},
'header-toolbar__container': {
height: 44,
},
};