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] Inner Block Navigate down through hierarchy #17547

Merged
merged 82 commits into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
6da1bf4
WIP: navigate down in the hierarchy of InnerBlocks
jbinda Sep 18, 2019
6387115
WIP: Navigation Dwon in Inner Block
jbinda Oct 8, 2019
e010328
merge master
jbinda Oct 8, 2019
09359f6
adjust style
jbinda Oct 8, 2019
a424c63
fix after merge
jbinda Oct 8, 2019
2e7204b
fix after merge
jbinda Oct 8, 2019
5dce162
playing with borders
jbinda Oct 8, 2019
76340c0
working full border
jbinda Oct 9, 2019
3295957
refactor v1
jbinda Oct 10, 2019
a28b17d
refactor v2
jbinda Oct 10, 2019
f00ad33
merge master
jbinda Oct 10, 2019
5326d44
fixed dashed border android
jbinda Oct 10, 2019
c70697c
refactor v3
jbinda Oct 10, 2019
eb7bed0
adjust button-block-appender margin
jbinda Oct 10, 2019
2fdedb7
refactor v4
jbinda Oct 10, 2019
d602fff
reefactor v5
jbinda Oct 10, 2019
497dcbc
refactor v6
jbinda Oct 10, 2019
ca22502
adjust for media text
jbinda Oct 11, 2019
dd06cba
adjust focus for media text
jbinda Oct 11, 2019
ec97815
refactor apply styles
jbinda Oct 11, 2019
3bf893b
merge master
jbinda Oct 11, 2019
8b02aae
adjust media text media container
jbinda Oct 11, 2019
4c1e1b9
pass isParentSelected prop to BlockEdit
jbinda Oct 11, 2019
e5976c0
adjust dim style
jbinda Oct 11, 2019
b54fa56
Move FloatingToolbar logic to get shippable temporary version
lukewalczak Oct 15, 2019
a6dcf70
fix after merge floating-toolbr
jbinda Oct 16, 2019
63b163f
style media-text and fix jumping behaviour
jbinda Oct 15, 2019
d7434b0
merge master
jbinda Oct 30, 2019
ed9a435
add getPrefferedColorScheme for dashed border
jbinda Nov 4, 2019
aafa452
enable FloatingToolbar for MediaText
jbinda Nov 4, 2019
dffabf9
refactor rich text handler
jbinda Nov 4, 2019
4576c6a
change dark-mode block holder border to blue
jbinda Nov 4, 2019
90ae894
dark-mode for group appender and placeholder
jbinda Nov 5, 2019
d8d4e1d
adjust margin for group placeholder
jbinda Nov 5, 2019
677aade
adjust innerblock margin for media-text
jbinda Nov 5, 2019
168c3a2
adjust group placeholder border color
jbinda Nov 5, 2019
d8b05e2
Merge remote-tracking branch 'origin/master' into rnmobile/navigate-down
jbinda Nov 5, 2019
e8464a0
adjust appender button color
jbinda Nov 6, 2019
7a500e1
re-activate the stacking vertically on Media & Text
jbinda Nov 6, 2019
132fa7a
Merge remote-tracking branch 'origin/master' into rnmobile/navigate-down
jbinda Nov 6, 2019
f94c828
CR changes
jbinda Nov 8, 2019
845f920
CR changes for Android RichText focus
jbinda Nov 12, 2019
35d8c8b
CR changes for MediaText margins
jbinda Nov 13, 2019
7eba06d
CR changes for getTree selector
jbinda Nov 13, 2019
48a62f4
CR changes: fix selection loop
jbinda Nov 15, 2019
65b8400
clean passing props after seletion loop issue fix
jbinda Nov 15, 2019
bd2a9fc
merge master
jbinda Nov 15, 2019
c072555
replace block specific text
jbinda Nov 15, 2019
f06f6af
replace block specific style
jbinda Nov 15, 2019
f2be82d
fix getParent selectors
jbinda Nov 18, 2019
e47908d
adjust selection logic
jbinda Nov 18, 2019
e8ae8b2
Merge remote-tracking branch 'origin/master' into rnmobile/navigate-down
jbinda Nov 18, 2019
84d8dad
fix hasInnerBlocks
jbinda Nov 18, 2019
014e3a0
refactor selectors
jbinda Nov 19, 2019
fdb2fae
Merge remote-tracking branch 'origin/master' into rnmobile/navigate-down
jbinda Nov 19, 2019
3b94490
refactor navigate-down logic
jbinda Nov 22, 2019
941baef
fix dimed style aplied
jbinda Nov 22, 2019
df0f5a4
add unit test for selector
jbinda Nov 25, 2019
8ab7ebe
use getBlockCount to check if block has children
jbinda Nov 25, 2019
3ebc50c
fix group margins, placeholder and appender
jbinda Nov 25, 2019
a035030
Merge branch 'rnmobile/try/navigate-down' into rnmobile/navigate-down
jbinda Nov 25, 2019
cd5b608
adjustments
jbinda Nov 25, 2019
bd5a1f8
add parameters to style
jbinda Nov 26, 2019
3219ad0
refactor for removing isGroupType
jbinda Nov 26, 2019
e3b540a
refactor group placeholder
jbinda Nov 26, 2019
f47e6dc
adjust media-text
jbinda Nov 27, 2019
ca7e08f
finalise group appender logic
jbinda Nov 27, 2019
8de07ef
selection and dim adjustments
jbinda Nov 27, 2019
93ae250
Merge remote-tracking branch 'origin/master' into rnmobile/navigate-down
jbinda Nov 28, 2019
662008e
handle semi-bordered
jbinda Nov 28, 2019
6414b89
refactor after tug review
jbinda Nov 29, 2019
524e0ca
Update packages/block-editor/src/store/selectors.js
jbinda Dec 3, 2019
7cf3950
Update packages/block-editor/src/store/selectors.js
jbinda Dec 3, 2019
5a456c9
Update packages/block-library/src/media-text/edit.native.js
jbinda Dec 3, 2019
061257a
export styles for media-text to stylesheet
jbinda Dec 3, 2019
7fb084a
fix order in test case
jbinda Dec 3, 2019
583650b
merge master
jbinda Dec 3, 2019
4574daf
refactor stylesheet in mediatext
jbinda Dec 3, 2019
22d5904
group appender logic
jbinda Dec 4, 2019
75482c5
@dratwas CR refactor
jbinda Dec 6, 2019
0814bb8
@dratwas CR refactor on descendant
jbinda Dec 6, 2019
7cb1ddb
Merge remote-tracking branch 'origin/master' into rnmobile/navigate-down
jbinda Dec 8, 2019
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 @@ -197,6 +197,7 @@ _Parameters_

- _state_ `Object`: Editor state.
- _clientId_ `string`: Block from which to find root client ID.
- _ascending_ `boolean`: Order results from bottom to top (true) or top to bottom (false).

_Returns_

Expand Down Expand Up @@ -390,6 +391,19 @@ _Returns_

- `?string`: Last block client ID in the multi-selection set.

<a name="getLowestCommonAncestorWithSelectedBlock" href="#getLowestCommonAncestorWithSelectedBlock">#</a> **getLowestCommonAncestorWithSelectedBlock**

Given a block client ID, returns the lowest common ancestor with selected client ID.

_Parameters_

- _state_ `Object`: Editor state.
- _clientId_ `string`: Block from which to find common ancestor client ID.

_Returns_

- `string`: Common ancestor client ID or undefined

<a name="getMultiSelectedBlockClientIds" href="#getMultiSelectedBlockClientIds">#</a> **getMultiSelectedBlockClientIds**

Returns the current multi-selection set of block client IDs, or an empty
Expand Down
12 changes: 12 additions & 0 deletions packages/base-styles/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ $block-container-side-padding: $block-side-ui-width + $block-padding + 2 * $bloc
$block-bg-padding--v: $block-padding + $block-spacing + $block-side-ui-clearance; // padding for Blocks with a background color (eg: paragraph or group)
$block-bg-padding--h: $block-side-ui-width + $block-side-ui-clearance; // padding for Blocks with a background color (eg: paragraph or group)

$block-edge-to-content: 16px;
$block-selected-margin: 3px;
$block-selected-border-width: 1px;
$block-selected-padding: 0;
$block-selected-child-margin: 5px;
$block-selected-child-border-width: 1px;
$block-selected-child-padding: 0;
$block-selected-to-content: $block-edge-to-content - $block-selected-margin - $block-selected-border-width;
$block-selected-child-to-content: $block-selected-to-content - $block-selected-child-margin - $block-selected-child-border-width;
$block-custom-appender-to-content: $block-edge-to-content - $block-selected-margin - $block-selected-child-margin + $block-selected-border-width;
$block-media-container-to-content: $block-selected-child-margin + $block-selected-border-width;

// Buttons & UI Widgets
$radius-round-rectangle: 4px;
$radius-round: 50%;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,16 @@ import { View, TouchableWithoutFeedback } from 'react-native';
* Internal dependencies
*/
import styles from './block-mobile-floating-toolbar.scss';
/**
* WordPress dependencies
*/
import { compose, withPreferredColorScheme } from '@wordpress/compose';
import { createSlotFill } from '@wordpress/components';

const { Fill, Slot } = createSlotFill( 'FloatingToolbar' );

const FloatingToolbarFill = ( { children, getStylesFromColorScheme } ) => {
const FloatingToolbar = ( { children } ) => {
return (
<Fill>
{ ( { innerFloatingToolbar } ) => {
const fillStyle = getStylesFromColorScheme( styles.floatingToolbarFillColor, styles.floatingToolbarFillColorDark );
return (
<TouchableWithoutFeedback>
<View
// Issue: `FloatingToolbar` placed above the first item in group is not touchable on Android.
// Temporary solution: Use `innerFloatingToolbar` to place `FloatingToolbar` over the first item in group.
// TODO: `{ top: innerFloatingToolbar ? 0 : -44 }` along with `innerFloatingToolbar` should be removed once issue is fixed.
style={ [ fillStyle, styles.floatingToolbarFill, { top: innerFloatingToolbar ? 0 : -44 } ] }
>{ children }
</View>
</TouchableWithoutFeedback>
);
} }

</Fill>
<TouchableWithoutFeedback>
<View
style={ styles.floatingToolbar }
>{ children }
</View>
</TouchableWithoutFeedback>
);
};

const FloatingToolbar = compose( withPreferredColorScheme )( FloatingToolbarFill );
FloatingToolbar.Slot = Slot;

export default FloatingToolbar;
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
.floatingToolbarFill {
.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;
top: -$floating-toolbar-height;
height: $floating-toolbar-height;
position: absolute;
align-items: center;
justify-content: center;
align-self: center;
margin-bottom: 8px;
}

.floatingToolbarFillColor {
Expand Down
174 changes: 139 additions & 35 deletions packages/block-editor/src/components/block-list/block.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { Component } from '@wordpress/element';
import { ToolbarButton, Toolbar } from '@wordpress/components';
import { withDispatch, withSelect } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import { compose, withPreferredColorScheme } from '@wordpress/compose';
import { getBlockType } from '@wordpress/blocks';
import { __, sprintf } from '@wordpress/i18n';

Expand All @@ -34,15 +34,12 @@ class BlockListBlock extends Component {

this.insertBlocksAfter = this.insertBlocksAfter.bind( this );
this.onFocus = this.onFocus.bind( this );

this.state = {
isFullyBordered: false,
};
}

onFocus() {
if ( ! this.props.isSelected ) {
this.props.onSelect();
const { firstToSelectId, isSelected, onSelect } = this.props;
if ( ! isSelected ) {
onSelect( firstToSelectId );
}
}

Expand Down Expand Up @@ -105,28 +102,108 @@ class BlockListBlock extends Component {
return blockName;
}

applySelectedBlockStyle() {
const {
hasChildren,
getStylesFromColorScheme,
isSmallScreen,
isRootListInnerBlockHolder,
} = this.props;

const fullSolidBorderStyle = { // define style for full border
...styles.fullSolidBordered,
...getStylesFromColorScheme( styles.solidBorderColor, styles.solidBorderColorDark ),
};

if ( hasChildren ) { // if block has children apply style for selected parent
return { ...styles.selectedParent, ...fullSolidBorderStyle };
}

// apply semi border selected style when screen is in vertical position
// and selected block does not have InnerBlock inside
if ( isSmallScreen && ! isRootListInnerBlockHolder ) {
return {
...styles.selectedRootLeaf,
...styles.semiSolidBordered,
...{ borderColor: fullSolidBorderStyle.borderColor },
};
}

/* selected block is one of below:
1. does not have children
2. is not on root list level
3. is an emty group block on root or nested level */
return { ...styles.selectedLeaf, ...fullSolidBorderStyle };
}

applyUnSelectedBlockStyle() {
const {
hasChildren,
isParentSelected,
isAncestorSelected,
hasParent,
getStylesFromColorScheme,
} = this.props;

// if block does not have parent apply neutral or full
// margins depending if block has children or not
if ( ! hasParent ) {
return hasChildren ? styles.neutral : styles.full;
}

if ( isParentSelected ) { // parent of a block is selected
const dashedBorderStyle = { // define style for dashed border
...styles.dashedBordered,
...getStylesFromColorScheme( styles.dashedBorderColor, styles.dashedBorderColorDark ),
};

// return apply childOfSelected or childOfSelectedLeaf
// margins depending if block has children or not
return hasChildren ?
{ ...styles.childOfSelected, ...dashedBorderStyle } :
{ ...styles.childOfSelectedLeaf, ...dashedBorderStyle };
}

if ( isAncestorSelected ) { // ancestor of a block is selected
return {
...styles.descendantOfSelectedLeaf,
...( hasChildren && styles.marginHorizontalNone ),
};
}

// if none of above condition are met return apply neutral or full
// margins depending if block has children or not
return hasChildren ? styles.neutral : styles.full;
}

applyBlockStyle() {
const {
isSelected,
isDimmed,
} = this.props;

return [
isSelected ? this.applySelectedBlockStyle() : this.applyUnSelectedBlockStyle(),
isDimmed && styles.dimmed,
];
}

render() {
const {
borderStyle,
clientId,
focusedBorderColor,
icon,
isSelected,
isValid,
showTitle,
title,
showFloatingToolbar,
parentId,
isFirstBlock,
isTouchable,
} = this.props;

const borderColor = isSelected ? focusedBorderColor : 'transparent';

const accessibilityLabel = this.getAccessibilityLabel();

return (
<>
{ showFloatingToolbar && ( ! isFirstBlock || parentId === '' ) && <FloatingToolbar.Slot /> }
{ showFloatingToolbar &&
( <FloatingToolbar>
<Toolbar passedStyle={ styles.toolbar }>
Expand All @@ -145,17 +222,12 @@ class BlockListBlock extends Component {
accessible={ ! isSelected }
accessibilityRole={ 'button' }
>
<View style={ [ styles.blockHolder, borderStyle, { borderColor } ] }>
{ showTitle && this.renderBlockTitle() }
<View
accessibilityLabel={ accessibilityLabel }
style={ [ ! isSelected && styles.blockContainer, isSelected && styles.blockContainerFocused ] }
>
{ isValid && this.getBlockForType() }
{ ! isValid &&
<BlockInvalidWarning blockTitle={ title } icon={ icon } />
}
</View>
<View
pointerEvents={ isTouchable ? 'auto' : 'box-only' }
accessibilityLabel={ accessibilityLabel }
style={ this.applyBlockStyle() }
jbinda marked this conversation as resolved.
Show resolved Hide resolved
>
{ isValid ? this.getBlockForType() : <BlockInvalidWarning blockTitle={ title } icon={ icon } /> }
{ isSelected && <BlockMobileToolbar clientId={ clientId } /> }
</View>
</TouchableWithoutFeedback>
Expand All @@ -172,13 +244,20 @@ export default compose( [
isBlockSelected,
__unstableGetBlockWithoutInnerBlocks,
getBlockHierarchyRootClientId,
getSelectedBlockClientId,
getBlock,
getBlockRootClientId,
getSelectedBlock,
getLowestCommonAncestorWithSelectedBlock,
getBlockParents,
getBlockCount,
} = select( 'core/block-editor' );

const {
getGroupingBlockName,
} = select( 'core/blocks' );

const order = getBlockIndex( clientId, rootClientId );
const isSelected = isBlockSelected( clientId );
const isFirstBlock = order === 0;
const isLastBlock = order === getBlocks().length - 1;
const block = __unstableGetBlockWithoutInnerBlocks( clientId );
const { name, attributes, isValid } = block || {};
Expand All @@ -187,18 +266,35 @@ export default compose( [
const icon = blockType.icon;
const getAccessibilityLabelExtra = blockType.__experimentalGetAccessibilityLabel;

const selectedBlock = getSelectedBlock();
const parentId = getBlockRootClientId( clientId );
const parentBlock = getBlock( parentId );

const isMediaText = selectedBlock && selectedBlock.name === 'core/media-text';
const isMediaTextParent = parentBlock && parentBlock.name === 'core/media-text';
const parents = getBlockParents( clientId, true );
const parentId = parents[ 0 ] || '';
dratwas marked this conversation as resolved.
Show resolved Hide resolved

const rootBlockId = getBlockHierarchyRootClientId( clientId );
const rootBlock = getBlock( rootBlockId );
const hasRootInnerBlocks = rootBlock.innerBlocks.length !== 0;

const showFloatingToolbar = isSelected && hasRootInnerBlocks && ! isMediaText && ! isMediaTextParent;
const showFloatingToolbar = isSelected && hasRootInnerBlocks;

const selectedBlockClientId = getSelectedBlockClientId();

const commonAncestor = getLowestCommonAncestorWithSelectedBlock( clientId );
const commonAncestorIndex = parents.indexOf( commonAncestor ) - 1;
const firstToSelectId = commonAncestor ? parents[ commonAncestorIndex ] : parents[ parents.length - 1 ];

const hasChildren = !! getBlockCount( clientId );
const hasParent = !! parentId;
const isParentSelected = selectedBlockClientId && selectedBlockClientId === parentId;
const isAncestorSelected = selectedBlockClientId && parents.includes( selectedBlockClientId );
const isSelectedBlockNested = !! getBlockRootClientId( selectedBlockClientId );

const selectedParents = selectedBlockClientId ? getBlockParents( selectedBlockClientId ) : [];
const isDescendantSelected = selectedParents.includes( clientId );
const isDescendantOfParentSelected = selectedParents.includes( parentId );
const isTouchable = isSelected || isDescendantOfParentSelected || isParentSelected || parentId === '';
const isDimmed = ! isSelected && isSelectedBlockNested && ! isAncestorSelected && ! isDescendantSelected && ( isDescendantOfParentSelected || rootBlockId === clientId );

const isInnerBlockHolder = name === getGroupingBlockName();
jbinda marked this conversation as resolved.
Show resolved Hide resolved
const isRootListInnerBlockHolder = ! isSelectedBlockNested && isInnerBlockHolder;

return {
icon,
Expand All @@ -207,13 +303,20 @@ export default compose( [
title,
attributes,
blockType,
isFirstBlock,
isLastBlock,
isSelected,
isValid,
getAccessibilityLabelExtra,
showFloatingToolbar,
parentId,
isParentSelected,
firstToSelectId,
hasChildren,
hasParent,
isAncestorSelected,
isTouchable,
isDimmed,
isRootListInnerBlockHolder,
};
} ),
withDispatch( ( dispatch, ownProps, { select } ) => {
Expand Down Expand Up @@ -259,4 +362,5 @@ export default compose( [
},
};
} ),
withPreferredColorScheme,
] )( BlockListBlock );
Loading