From 8acbb4f9646f6b3ad8687f60e7816bf88c13ae14 Mon Sep 17 00:00:00 2001 From: jbinda Date: Wed, 22 Apr 2020 08:38:45 +0200 Subject: [PATCH] [RNMobile] Fixed position of `FloatingToolbar` on the bottom of the screen (#21446) * handle FloatingToolbar absolute positioning * support RTL mode by rotate the icons * move FloatingToolbar to packages/components/src/mobile/floating-toolbar * render FloatingToolbar on top for Android and on bottom for iOS * change FloatingToolbar backgroundColor to #e2e2e2 --- packages/base-styles/_variables.scss | 2 + .../block-mobile-floating-toolbar.native.js | 19 ----- .../block-mobile-floating-toolbar.native.scss | 24 ------ .../src/components/block-list/block.native.js | 33 -------- .../components/block-list/block.native.scss | 17 ---- .../block-list/breadcrumb.native.js | 11 ++- .../src/components/block-list/index.native.js | 25 +++++- .../components/block-list/style.native.scss | 4 + .../block-list/subdirectory-icon.js | 7 +- .../floatingToolbar.android.scss | 4 + .../floating-toolbar/floatingToolbar.ios.scss | 3 + .../floating-toolbar/index.native.js | 77 +++++++++++++++++++ .../nav-up-icon.js | 3 +- .../floating-toolbar/styles.native.scss | 43 +++++++++++ .../src/components/index.native.js | 1 + .../src/components/layout/index.native.js | 5 ++ 16 files changed, 176 insertions(+), 102 deletions(-) delete mode 100644 packages/block-editor/src/components/block-list/block-mobile-floating-toolbar.native.js delete mode 100644 packages/block-editor/src/components/block-list/block-mobile-floating-toolbar.native.scss create mode 100644 packages/block-editor/src/components/floating-toolbar/floatingToolbar.android.scss create mode 100644 packages/block-editor/src/components/floating-toolbar/floatingToolbar.ios.scss create mode 100644 packages/block-editor/src/components/floating-toolbar/index.native.js rename packages/block-editor/src/components/{block-list => floating-toolbar}/nav-up-icon.js (80%) create mode 100644 packages/block-editor/src/components/floating-toolbar/styles.native.scss diff --git a/packages/base-styles/_variables.scss b/packages/base-styles/_variables.scss index 8935761075ed9a..276bd120ab0b59 100644 --- a/packages/base-styles/_variables.scss +++ b/packages/base-styles/_variables.scss @@ -52,6 +52,8 @@ $admin-sidebar-width-collapsed: 36px; $modal-min-width: 360px; $spinner-size: 18px; $mobile-header-toolbar-height: 44px; +$mobile-floating-toolbar-height: 44px; +$mobile-floating-toolbar-margin: 8px; /** diff --git a/packages/block-editor/src/components/block-list/block-mobile-floating-toolbar.native.js b/packages/block-editor/src/components/block-list/block-mobile-floating-toolbar.native.js deleted file mode 100644 index fc8876253734c2..00000000000000 --- a/packages/block-editor/src/components/block-list/block-mobile-floating-toolbar.native.js +++ /dev/null @@ -1,19 +0,0 @@ -/** - * External dependencies - */ -import { View, TouchableWithoutFeedback } from 'react-native'; - -/** - * Internal dependencies - */ -import styles from './block-mobile-floating-toolbar.scss'; - -const FloatingToolbar = ( { children } ) => { - return ( - - { children } - - ); -}; - -export default FloatingToolbar; diff --git a/packages/block-editor/src/components/block-list/block-mobile-floating-toolbar.native.scss b/packages/block-editor/src/components/block-list/block-mobile-floating-toolbar.native.scss deleted file mode 100644 index 5b12591ec44361..00000000000000 --- a/packages/block-editor/src/components/block-list/block-mobile-floating-toolbar.native.scss +++ /dev/null @@ -1,24 +0,0 @@ -$floating-toolbar-height: 44; - -.floatingToolbar { - background-color: $dark-gray-500; - margin: auto; - min-width: 100; - max-height: $floating-toolbar-height; - border-radius: 22px; - flex-direction: row; - z-index: 100; - height: $floating-toolbar-height; - align-items: center; - justify-content: center; - align-self: center; - margin-bottom: 8px; -} - -.floatingToolbarFillColor { - background-color: rgba(#1d2327, 0.85); -} - -.floatingToolbarFillColorDark { - background-color: rgba(#3c434a, 0.85); -} diff --git a/packages/block-editor/src/components/block-list/block.native.js b/packages/block-editor/src/components/block-list/block.native.js index 5e138de2e909ec..773c6d19fb9913 100644 --- a/packages/block-editor/src/components/block-list/block.native.js +++ b/packages/block-editor/src/components/block-list/block.native.js @@ -7,14 +7,12 @@ import { View, Text, TouchableWithoutFeedback } from 'react-native'; * WordPress dependencies */ import { Component } from '@wordpress/element'; -import { ToolbarButton, Toolbar } from '@wordpress/components'; import { withDispatch, withSelect } from '@wordpress/data'; import { compose, withPreferredColorScheme } from '@wordpress/compose'; import { getBlockType, __experimentalGetAccessibleBlockLabel as getAccessibleBlockLabel, } from '@wordpress/blocks'; -import { __ } from '@wordpress/i18n'; /** * Internal dependencies @@ -23,9 +21,6 @@ import styles from './block.scss'; import BlockEdit from '../block-edit'; import BlockInvalidWarning from './block-invalid-warning'; import BlockMobileToolbar from '../block-mobile-toolbar'; -import FloatingToolbar from './block-mobile-floating-toolbar'; -import Breadcrumbs from './breadcrumb'; -import NavigateUpSVG from './nav-up-icon'; class BlockListBlock extends Component { constructor() { @@ -91,15 +86,11 @@ class BlockListBlock extends Component { isValid, order, title, - parentId, isDimmed, isTouchable, onDeleteBlock, isStackedHorizontally, - hasParent, isParentSelected, - onSelect, - showFloatingToolbar, getStylesFromColorScheme, marginVertical, marginHorizontal, @@ -124,21 +115,6 @@ class BlockListBlock extends Component { style={ { flex: 1 } } accessibilityLabel={ accessibilityLabel } > - { showFloatingToolbar && ( - - { hasParent && ( - - onSelect( parentId ) } - icon={ NavigateUpSVG } - /> - - - ) } - - - ) } { diff --git a/packages/block-editor/src/components/block-list/block.native.scss b/packages/block-editor/src/components/block-list/block.native.scss index 0d1c60fe4f1f19..aa3d6d1248f595 100644 --- a/packages/block-editor/src/components/block-list/block.native.scss +++ b/packages/block-editor/src/components/block-list/block.native.scss @@ -41,23 +41,6 @@ min-height: 50px; } -.toolbar { - border-left-width: 0; - margin-right: auto; - padding-left: 2px; - height: 44px; -} - -.pipe { - margin-top: auto; - margin-bottom: auto; - margin-left: 2px; - height: 28px; - width: 1px; - background-color: #e9eff3; - opacity: 0.4; -} - .neutralToolbar { margin-left: -$block-edge-to-content; margin-right: -$block-edge-to-content; diff --git a/packages/block-editor/src/components/block-list/breadcrumb.native.js b/packages/block-editor/src/components/block-list/breadcrumb.native.js index 0084d8485a326b..027b93abf6b7d3 100644 --- a/packages/block-editor/src/components/block-list/breadcrumb.native.js +++ b/packages/block-editor/src/components/block-list/breadcrumb.native.js @@ -9,7 +9,7 @@ import { getBlockType } from '@wordpress/blocks'; /** * External dependencies */ -import { View, Text, TouchableOpacity } from 'react-native'; +import { View, Text, TouchableOpacity, I18nManager } from 'react-native'; /** * Internal dependencies @@ -50,7 +50,10 @@ const BlockBreadcrumb = ( { fill={ styles.icon.color } />, - + , ] } ( +const Subdirectory = ( { isRTL, ...extraProps } ) => ( ( viewBox="0 0 20 20" { ...extraProps } > - + ); export default Subdirectory; diff --git a/packages/block-editor/src/components/floating-toolbar/floatingToolbar.android.scss b/packages/block-editor/src/components/floating-toolbar/floatingToolbar.android.scss new file mode 100644 index 00000000000000..e593022f0db97e --- /dev/null +++ b/packages/block-editor/src/components/floating-toolbar/floatingToolbar.android.scss @@ -0,0 +1,4 @@ +.floatingToolbarOffset { + top: 0; + margin-top: 8px; +} diff --git a/packages/block-editor/src/components/floating-toolbar/floatingToolbar.ios.scss b/packages/block-editor/src/components/floating-toolbar/floatingToolbar.ios.scss new file mode 100644 index 00000000000000..c25157540286d0 --- /dev/null +++ b/packages/block-editor/src/components/floating-toolbar/floatingToolbar.ios.scss @@ -0,0 +1,3 @@ +.floatingToolbarOffset { + top: - ($mobile-floating-toolbar-height + $mobile-floating-toolbar-margin); +} diff --git a/packages/block-editor/src/components/floating-toolbar/index.native.js b/packages/block-editor/src/components/floating-toolbar/index.native.js new file mode 100644 index 00000000000000..3d3b49f0d9471d --- /dev/null +++ b/packages/block-editor/src/components/floating-toolbar/index.native.js @@ -0,0 +1,77 @@ +/** + * External dependencies + */ +import { View, TouchableWithoutFeedback, I18nManager } from 'react-native'; + +/** + * WordPress dependencies + */ +import { ToolbarButton, Toolbar } from '@wordpress/components'; +import { withSelect, withDispatch } from '@wordpress/data'; +import { compose } from '@wordpress/compose'; +import { __ } from '@wordpress/i18n'; + +/** + * Internal dependencies + */ +import styles from './styles.scss'; +import NavigateUpSVG from './nav-up-icon'; +import Breadcrumb from '../block-list/breadcrumb.native'; + +const FloatingToolbar = ( { + selectedClientId, + parentId, + showFloatingToolbar, + onNavigateUp, +} ) => + !! showFloatingToolbar && ( + + + { !! parentId && ( + + onNavigateUp( parentId ) } + icon={ + + } + /> + + + ) } + + + + ); + +export default compose( [ + withSelect( ( select ) => { + const { + getSelectedBlockClientId, + getBlockHierarchyRootClientId, + getBlockRootClientId, + getBlockCount, + } = select( 'core/block-editor' ); + + const selectedClientId = getSelectedBlockClientId(); + + if ( ! selectedClientId ) return; + + const rootBlockId = getBlockHierarchyRootClientId( selectedClientId ); + + return { + selectedClientId, + showFloatingToolbar: !! getBlockCount( rootBlockId ), + parentId: getBlockRootClientId( selectedClientId ), + }; + } ), + withDispatch( ( dispatch ) => { + const { selectBlock } = dispatch( 'core/block-editor' ); + + return { + onNavigateUp( clientId, initialPosition ) { + selectBlock( clientId, initialPosition ); + }, + }; + } ), +] )( FloatingToolbar ); diff --git a/packages/block-editor/src/components/block-list/nav-up-icon.js b/packages/block-editor/src/components/floating-toolbar/nav-up-icon.js similarity index 80% rename from packages/block-editor/src/components/block-list/nav-up-icon.js rename to packages/block-editor/src/components/floating-toolbar/nav-up-icon.js index ae1d897660af7b..029b667dfb498c 100644 --- a/packages/block-editor/src/components/block-list/nav-up-icon.js +++ b/packages/block-editor/src/components/floating-toolbar/nav-up-icon.js @@ -3,7 +3,7 @@ */ import { SVG, Path } from '@wordpress/components'; -const NavigateUp = ( +const NavigateUp = ( { isRTL } ) => ( ); diff --git a/packages/block-editor/src/components/floating-toolbar/styles.native.scss b/packages/block-editor/src/components/floating-toolbar/styles.native.scss new file mode 100644 index 00000000000000..8a4b7a1f821374 --- /dev/null +++ b/packages/block-editor/src/components/floating-toolbar/styles.native.scss @@ -0,0 +1,43 @@ +@import "floatingToolbar"; + +.floatingToolbar { + position: absolute; + @extend .floatingToolbarOffset; + background-color: $background-dark-elevated; + margin-left: auto; + margin-right: auto; + min-width: 100; + max-height: $mobile-floating-toolbar-height; + border-radius: 22px; + flex-direction: row; + z-index: 100; + height: $mobile-floating-toolbar-height; + align-items: center; + justify-content: center; + align-self: center; +} + +.floatingToolbarFillColor { + background-color: $background-dark-elevated; +} + +.floatingToolbarFillColorDark { + background-color: $background-dark-elevated; +} + +.toolbar { + border-left-width: 0; + margin-right: auto; + padding-left: 2px; + height: $mobile-floating-toolbar-height; +} + +.pipe { + margin-top: auto; + margin-bottom: auto; + margin-left: 2px; + height: 28px; + width: 1px; + background-color: #e9eff3; + opacity: 0.4; +} diff --git a/packages/block-editor/src/components/index.native.js b/packages/block-editor/src/components/index.native.js index d859f6d65b6f67..f2e9e2ed82c688 100644 --- a/packages/block-editor/src/components/index.native.js +++ b/packages/block-editor/src/components/index.native.js @@ -49,6 +49,7 @@ export { default as DefaultBlockAppender } from './default-block-appender'; export { default as __unstableEditorStyles } from './editor-styles'; export { default as Inserter } from './inserter'; export { Block as __experimentalBlock } from './block-list/block-wrapper'; +export { default as FloatingToolbar } from './floating-toolbar'; // State Related Components export { default as BlockEditorProvider } from './provider'; diff --git a/packages/edit-post/src/components/layout/index.native.js b/packages/edit-post/src/components/layout/index.native.js index 9384a0da52b2c0..94291b0db06e35 100644 --- a/packages/edit-post/src/components/layout/index.native.js +++ b/packages/edit-post/src/components/layout/index.native.js @@ -14,6 +14,7 @@ import { BottomSheetSettings, __experimentalPageTemplatePicker, __experimentalWithPageTemplatePicker, + FloatingToolbar, } from '@wordpress/block-editor'; import { compose, withPreferredColorScheme } from '@wordpress/compose'; import { HTMLTextInput, KeyboardAvoidingView } from '@wordpress/components'; @@ -131,6 +132,9 @@ class Layout extends Component { ) } > { isHtmlView ? this.renderHTML() : this.renderVisual() } + { ! isHtmlView && Platform.OS === 'android' && ( + + ) } ) } + { Platform.OS === 'ios' && }