Skip to content

Commit

Permalink
[RNMobile] Refactor BlockToolbar follow-up PR (#16906)
Browse files Browse the repository at this point in the history
* Keyboard is already hidden with clearSelectedBlock

* Hide Keyboard when switching mode

* require clearSelectedBlock from core/block-editor instead of core/editor

* require clearSelectedBlock from core/block-editor instead of core/editor
  • Loading branch information
Tug authored and gziolo committed Aug 29, 2019
1 parent 44fcc1c commit 0f429db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { ScrollView, Keyboard, Platform, View } from 'react-native';
import { ScrollView, View } from 'react-native';

/**
* WordPress dependencies
Expand Down Expand Up @@ -31,14 +31,6 @@ function HeaderToolbar( {
showKeyboardHideButton,
clearSelectedBlock,
} ) {
const hideKeyboard = () => {
clearSelectedBlock();
if ( Platform.OS === 'android' ) {
// Avoiding extra blur calls on iOS but still needed for android.
Keyboard.dismiss();
}
};

return (
<View style={ styles.container }>
<ScrollView
Expand Down Expand Up @@ -75,7 +67,7 @@ function HeaderToolbar( {
<ToolbarButton
title={ __( 'Hide keyboard' ) }
icon="keyboard-hide"
onClick={ hideKeyboard }
onClick={ clearSelectedBlock }
extraProps={ { hint: __( 'Tap to hide the keyboard' ) } }
/>
</Toolbar>
Expand All @@ -96,7 +88,7 @@ export default compose( [
withDispatch( ( dispatch ) => ( {
redo: dispatch( 'core/editor' ).redo,
undo: dispatch( 'core/editor' ).undo,
clearSelectedBlock: dispatch( 'core/editor' ).clearSelectedBlock,
clearSelectedBlock: dispatch( 'core/block-editor' ).clearSelectedBlock,
} ) ),
withViewportMatch( { isLargeViewport: 'medium' } ),
] )( HeaderToolbar );
6 changes: 6 additions & 0 deletions packages/editor/src/components/provider/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ class NativeEditorProvider extends Component {
const { mode, switchMode } = this.props;
// refresh html content first
this.serializeToNativeAction();
// make sure to blur the selected block and dismiss the keyboard
this.props.clearSelectedBlock();
switchMode( mode === 'visual' ? 'text' : 'visual' );
}

Expand Down Expand Up @@ -161,11 +163,15 @@ export default compose( [
editPost,
resetEditorBlocks,
} = dispatch( 'core/editor' );
const {
clearSelectedBlock,
} = dispatch( 'core/block-editor' );
const {
switchEditorMode,
} = dispatch( 'core/edit-post' );

return {
clearSelectedBlock,
editTitle( title ) {
editPost( { title } );
},
Expand Down

0 comments on commit 0f429db

Please sign in to comment.