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

Port InlineToolbar to Gutenberg as BlockMobileToolbar #1133

Merged
merged 10 commits into from
Jun 18, 2019
65 changes: 3 additions & 62 deletions src/block-management/block-holder.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,15 @@ import {
View,
Text,
TouchableWithoutFeedback,
Keyboard,
} from 'react-native';
import {
requestImageUploadCancel,
} from 'react-native-gutenberg-bridge';

/**
* WordPress dependencies
*/
import { withDispatch, withSelect } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import { addAction, hasAction, removeAction } from '@wordpress/hooks';
import { getBlockType } from '@wordpress/blocks';
import { BlockEdit, BlockInvalidWarning } from '@wordpress/block-editor';
import { BlockEdit, BlockInvalidWarning, BlockMobileToolbar } from '@wordpress/block-editor';
import { __, sprintf } from '@wordpress/i18n';
import { coreBlocks } from '@wordpress/block-library';

Expand All @@ -33,7 +28,6 @@ import { coreBlocks } from '@wordpress/block-library';
*/
import type { BlockType } from '../store/types';
import styles from './block-holder.scss';
import InlineToolbar, { InlineToolbarActions } from './inline-toolbar';

type PropsType = BlockType & {
icon: mixed,
Expand Down Expand Up @@ -81,32 +75,6 @@ export class BlockHolder extends React.Component<PropsType, StateType> {
}
};

onRemoveBlockCheckUpload = ( mediaId: number ) => {
if ( hasAction( 'blocks.onRemoveBlockCheckUpload' ) ) {
// now remove the action as it's a one-shot use and won't be needed anymore
removeAction( 'blocks.onRemoveBlockCheckUpload', 'gutenberg-mobile/blocks' );
requestImageUploadCancel( mediaId );
}
};

onInlineToolbarButtonPressed = ( button: number ) => {
Keyboard.dismiss();
switch ( button ) {
case InlineToolbarActions.UP:
this.props.moveBlockUp();
break;
case InlineToolbarActions.DOWN:
this.props.moveBlockDown();
break;
case InlineToolbarActions.DELETE:
// adding a action that will exist for as long as it takes for the block to be removed and the component unmounted
// this acts as a flag for the code using the action to know of its existence
addAction( 'blocks.onRemoveBlockCheckUpload', 'gutenberg-mobile/blocks', this.onRemoveBlockCheckUpload );
this.props.removeBlock();
break;
}
};

insertBlocksAfter = ( blocks: Array<Object> ) => {
this.props.onInsertBlocks( blocks, this.props.order + 1 );

Expand All @@ -116,21 +84,6 @@ export class BlockHolder extends React.Component<PropsType, StateType> {
}
};

renderToolbar() {
if ( ! this.props.isSelected ) {
return null;
}

return (
<InlineToolbar
clientId={ this.props.clientId }
onButtonPressed={ this.onInlineToolbarButtonPressed }
canMoveUp={ ! this.props.isFirstBlock }
canMoveDown={ ! this.props.isLastBlock }
/>
);
}

getBlockForType() {
return (
<BlockEdit
Expand Down Expand Up @@ -182,7 +135,7 @@ export class BlockHolder extends React.Component<PropsType, StateType> {
}

render() {
const { isSelected, borderStyle, focusedBorderColor, isValid, title, icon } = this.props;
const { clientId, isSelected, borderStyle, focusedBorderColor, isValid, title, icon } = this.props;

const borderColor = isSelected ? focusedBorderColor : 'transparent';

Expand All @@ -207,7 +160,7 @@ export class BlockHolder extends React.Component<PropsType, StateType> {
<BlockInvalidWarning blockTitle={ title } icon={ icon } />
}
</View>
{ this.renderToolbar() }
{ isSelected && <BlockMobileToolbar clientId={ clientId } /> }
</View>

</TouchableWithoutFeedback>
Expand Down Expand Up @@ -258,9 +211,6 @@ export default compose( [
const {
insertBlocks,
mergeBlocks,
moveBlocksDown,
moveBlocksUp,
removeBlock,
replaceBlocks,
selectBlock,
updateBlockAttributes,
Expand All @@ -286,15 +236,6 @@ export default compose( [
}
}
},
moveBlockDown() {
moveBlocksDown( ownProps.clientId );
},
moveBlockUp() {
moveBlocksUp( ownProps.clientId );
},
removeBlock() {
removeBlock( ownProps.clientId );
},
onInsertBlocks( blocks: Array<Object>, index: number ) {
insertBlocks( blocks, index, ownProps.rootClientId );
},
Expand Down
4 changes: 2 additions & 2 deletions src/block-management/block-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import BlockHolder from './block-holder';
import type { BlockType } from '../store/types';
import styles from './block-manager.scss';
import blockHolderStyles from './block-holder.scss';
import inlineToolbarStyles from './inline-toolbar/style.scss';
import HTMLTextInput from '../components/html-text-input';
import SafeArea from 'react-native-safe-area';

const blockMobileToolbarHeight = 44;
const toolbarHeight = 44;

type PropsType = {
Expand Down Expand Up @@ -257,7 +257,7 @@ export class BlockManager extends React.Component<PropsType, StateType> {
accessibilityLabel="block-list"
innerRef={ this.scrollViewInnerRef }
blockToolbarHeight={ toolbarHeight }
innerToolbarHeight={ inlineToolbarStyles.toolbar.height }
innerToolbarHeight={ blockMobileToolbarHeight }
safeAreaBottomInset={ this.state.safeAreaBottomInset }
parentHeight={ this.state.rootViewHeight }
keyboardShouldPersistTaps="always"
Expand Down
12 changes: 0 additions & 12 deletions src/block-management/inline-toolbar/actions.js

This file was deleted.

50 changes: 0 additions & 50 deletions src/block-management/inline-toolbar/button.js

This file was deleted.

118 changes: 0 additions & 118 deletions src/block-management/inline-toolbar/index.js

This file was deleted.

29 changes: 0 additions & 29 deletions src/block-management/inline-toolbar/style.scss

This file was deleted.