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] FloatingToolbar #17399

Merged
merged 41 commits into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
635108e
[RNMobile] Native mobile release v1.11.0 (#17181)
etoledom Aug 28, 2019
643c1b2
Activate Travis CI on rnmobile/master branch (#17229)
etoledom Aug 28, 2019
a78f204
Add native support for the MediaText block (#16305)
Tug Aug 29, 2019
3db95b7
MediaUpload and MediaPlaceholder unify props (#17145)
dratwas Aug 30, 2019
7aa44a2
Unify media placeholder and upload props within media-text (#17268)
lukewalczak Aug 30, 2019
f9fa455
[RNMobile] Fix dismiss keyboard button for the post title (#17260)
geriux Aug 30, 2019
7b12673
Recover border colors (#17269)
etoledom Aug 30, 2019
14d482b
[RNMobile] Insure tapping at end of post inserts at end
mchowning Aug 6, 2019
89664eb
Support group block on mobile (#17251)
lukewalczak Sep 3, 2019
fc8c3da
Remove redundant bg color within button appender (#17325)
lukewalczak Sep 4, 2019
264b178
[RNMobile] DarkMode improvements (#17309)
etoledom Sep 4, 2019
654e162
Add FloatingToolbar component
lukewalczak Sep 10, 2019
111059c
Add visible overflow to flat list wrapper
lukewalczak Sep 10, 2019
89ed4d7
Remove useless codelines
lukewalczak Sep 10, 2019
900233d
Update test
lukewalczak Sep 10, 2019
2deb517
Trigger CI
lukewalczak Sep 10, 2019
6106f27
Remove redundant conditions
lukewalczak Sep 10, 2019
67c5cca
Trigger CI
lukewalczak Sep 10, 2019
648a1b9
[RNMobile] Add autosave to mobile apps (#17329)
daniloercoli Sep 19, 2019
9659a73
Trigger CI
lukewalczak Sep 23, 2019
e99d365
Add isAppender functionality on mobile (#17195)
lukewalczak Sep 25, 2019
69da85e
Autosave monitor - Make the mobile editor ping the native at each key…
daniloercoli Sep 25, 2019
ae6d2ce
[RNMobile] Refactor Dark Mode HOC (#17552)
Tug Sep 25, 2019
1c9b133
Add missing heading levels to the UI (H4, H5, H6) (#17533)
SergioEstevao Sep 25, 2019
8752302
Fix FloatingToolbar for the first item in FlatList
lukewalczak Sep 26, 2019
e3a4f1a
Small cleanup
lukewalczak Sep 26, 2019
df025a6
Fix lint issue (#17598)
lukewalczak Sep 26, 2019
d8b0d83
Fix list filter on paste for RN mobile. (#17550)
SergioEstevao Sep 26, 2019
59f0d5f
Merge branch 'rnmobile/master' into rnmobile/floating-toolbar
lukewalczak Sep 26, 2019
f3085c1
[RNMobile] Move MediaUploadPorgress to its own component folder (#17392)
geriux Sep 27, 2019
636bf83
Working on Android toolbar behaviour
lukewalczak Sep 27, 2019
95acf23
Rnmobile/fix link editing on start (#17631)
SergioEstevao Sep 30, 2019
47cd600
Small code refactor
lukewalczak Sep 30, 2019
6449038
Use temporary solution for first item in group
lukewalczak Oct 1, 2019
d0ba0fe
Merge branch 'rnmobile/master' into rnmobile/floating-toolbar
lukewalczak Oct 1, 2019
c70edc5
Merge branch 'master' into rnmobile/floating-toolbar
lukewalczak Oct 1, 2019
300a8a5
Merge fix
lukewalczak Oct 1, 2019
a9d7489
Merge fix
lukewalczak Oct 1, 2019
2695248
Make FloatingToolbar conditional to show flag
lukewalczak Oct 1, 2019
d2a07ec
Fix after merging
lukewalczak Oct 1, 2019
e911f5d
Add check for Media&Text block
lukewalczak Oct 1, 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
@@ -0,0 +1,40 @@
/**
* External dependencies
*/
import { View, TouchableWithoutFeedback } from 'react-native';

/**
* Internal dependencies
*/
import styles from './block-mobile-floating-toolbar.scss';
/**
* WordPress dependencies
*/
import { createSlotFill } from '@wordpress/components';

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

function FloatingToolbar( { children } ) {
return (
<Fill>
{ ( { innerFloatingToolbar } ) => {
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={ [ styles.floatingToolbarFill, { top: innerFloatingToolbar ? 0 : -44 } ] }
>{ children }
</View>
</TouchableWithoutFeedback>
);
} }

</Fill>
);
}

FloatingToolbar.Slot = Slot;

export default FloatingToolbar;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.floatingToolbarFill {
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;
}
61 changes: 44 additions & 17 deletions packages/block-editor/src/components/block-list/block.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ 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';

class BlockListBlock extends Component {
constructor() {
Expand Down Expand Up @@ -111,32 +112,39 @@ class BlockListBlock extends Component {
isValid,
showTitle,
title,
showFloatingToolbar,
parentId,
isFirstBlock,
} = this.props;

const borderColor = isSelected ? focusedBorderColor : 'transparent';

const accessibilityLabel = this.getAccessibilityLabel();

return (
<TouchableWithoutFeedback
onPress={ this.onFocus }
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 &&
<>
{ showFloatingToolbar && ( ! isFirstBlock || parentId === '' ) && <FloatingToolbar.Slot /> }
{ showFloatingToolbar && <FloatingToolbar /> }
<TouchableWithoutFeedback
onPress={ this.onFocus }
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>
{ isSelected && <BlockMobileToolbar clientId={ clientId } /> }
</View>
{ isSelected && <BlockMobileToolbar clientId={ clientId } /> }
</View>
</TouchableWithoutFeedback>
</TouchableWithoutFeedback>
</>
);
}
}
Expand All @@ -148,6 +156,10 @@ export default compose( [
getBlocks,
isBlockSelected,
__unstableGetBlockWithoutInnerBlocks,
getBlockHierarchyRootClientId,
getBlock,
getBlockRootClientId,
getSelectedBlock,
} = select( 'core/block-editor' );
const order = getBlockIndex( clientId, rootClientId );
const isSelected = isBlockSelected( clientId );
Expand All @@ -160,6 +172,19 @@ 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 rootBlockId = getBlockHierarchyRootClientId( clientId );
const rootBlock = getBlock( rootBlockId );
const hasRootInnerBlocks = rootBlock.innerBlocks.length !== 0;

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

return {
icon,
name: name || 'core/missing',
Expand All @@ -172,6 +197,8 @@ export default compose( [
isSelected,
isValid,
getAccessibilityLabelExtra,
showFloatingToolbar,
parentId,
};
} ),
withDispatch( ( dispatch, ownProps, { select } ) => {
Expand Down
19 changes: 16 additions & 3 deletions packages/block-editor/src/components/block-list/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { KeyboardAwareFlatList, ReadableContentView } from '@wordpress/component
import styles from './style.scss';
import BlockListBlock from './block';
import BlockListAppender from '../block-list-appender';
import FloatingToolbar from './block-mobile-floating-toolbar';

const innerToolbarHeight = 44;

Expand Down Expand Up @@ -69,13 +70,15 @@ export class BlockList extends Component {
}

render() {
const { clearSelectedBlock, blockClientIds, isFullyBordered, title, header, withFooter = true, renderAppender } = this.props;
const { clearSelectedBlock, blockClientIds, isFullyBordered, title, header, withFooter = true, renderAppender, isFirstBlock, selectedBlockParentId } = this.props;

const showFloatingToolbar = isFirstBlock && selectedBlockParentId !== '';
return (
<View
style={ { flex: 1 } }
onAccessibilityEscape={ clearSelectedBlock }
>
{ showFloatingToolbar && <FloatingToolbar.Slot fillProps={ { innerFloatingToolbar: showFloatingToolbar } } /> }
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need to change this file? considering we are rendering the first one inside the bounds. I know this is a temp fix but still I'd want to change minimum code to avoid any side effects until we find a better solution.

Copy link
Member Author

@lukewalczak lukewalczak Oct 1, 2019

Choose a reason for hiding this comment

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

If we want to simplify it to the minimum we don't need to use slot/fill, however, I've decided to keep this for the next investigations.

<KeyboardAwareFlatList
{ ...( Platform.OS === 'android' ? { removeClippedSubviews: false } : {} ) } // Disable clipping on Android to fix focus losing. See https://github.com/wordpress-mobile/gutenberg-mobile/pull/741#issuecomment-472746541
accessibilityLabel="block-list"
Expand All @@ -93,6 +96,9 @@ export class BlockList extends Component {
ListHeaderComponent={ header }
ListEmptyComponent={ this.renderDefaultBlockAppender }
ListFooterComponent={ withFooter && this.renderBlockListFooter }
getItemLayout={ ( data, index ) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need this considering the current temporary fix? If we don't let's remove it to avoid having unexpected side effects

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it's still needed to get working properly FloatingToolbar on Android.

return { length: 0, offset: 0, index };
} }
/>

{ renderAppender && blockClientIds.length > 0 &&
Expand Down Expand Up @@ -166,6 +172,7 @@ export default compose( [
getBlockInsertionPoint,
isBlockInsertionPointVisible,
getSelectedBlock,
getBlockRootClientId,
} = select( 'core/block-editor' );

const selectedBlockClientId = getSelectedBlockClientId();
Expand All @@ -182,7 +189,12 @@ export default compose( [
);
};

const selectedBlockIndex = getBlockIndex( selectedBlockClientId );
const selectedBlockIndex = getBlockIndex( selectedBlockClientId, rootClientId );

const isFirstBlock = selectedBlockIndex === 0;

const selectedBlockParentId = getBlockRootClientId( selectedBlockClientId );

const shouldShowBlockAtIndex = ( index ) => {
const shouldHideBlockAtIndex = (
! isSelectedGroup && blockInsertionPointIsVisible &&
Expand All @@ -201,6 +213,8 @@ export default compose( [
shouldShowBlockAtIndex,
shouldShowInsertionPoint,
selectedBlockClientId,
isFirstBlock,
selectedBlockParentId,
};
} ),
withDispatch( ( dispatch ) => {
Expand All @@ -218,4 +232,3 @@ export default compose( [
} ),
withPreferredColorScheme,
] )( BlockList );

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const KeyboardAwareFlatList = ( {
...listProps
} ) => (
<KeyboardAwareScrollView
style={ { flex: 1 } }
style={ { flex: 1, overflow: 'visible' } }
keyboardDismissMode="none"
enableResetScrollToCoords={ false }
keyboardShouldPersistTaps="handled"
Expand Down