Skip to content

Commit

Permalink
[Mobile] - Fix splitting/merging of Paragraph and Heading (#29502)
Browse files Browse the repository at this point in the history
* Wip: Mobile RichText - Updating old value after splitting

* Mobile - Fix splitting/merging issues and keyboard jumpiness on Android

* Mobile - RichText - Add isIOS check for componentDidUpdate and use blockEditorStore

* Mobile - RichText - Prevent onTextUpdate on Android
  • Loading branch information
Gerardo Pacheco committed Mar 4, 2021
1 parent c085da1 commit a14915f
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/rich-text/src/component/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* WordPress dependencies
*/
import RCTAztecView from '@wordpress/react-native-aztec';
import { View, Platform } from 'react-native';
import { View, Platform, InteractionManager } from 'react-native';
import {
showUserSuggestions,
showXpostSuggestions,
Expand All @@ -18,7 +18,10 @@ import memize from 'memize';
/**
* WordPress dependencies
*/
import { BlockFormatControls } from '@wordpress/block-editor';
import {
BlockFormatControls,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { Component } from '@wordpress/element';
import { compose, withPreferredColorScheme } from '@wordpress/compose';
import { withSelect } from '@wordpress/data';
Expand Down Expand Up @@ -556,6 +559,7 @@ export class RichText extends Component {

// Check if value is up to date with latest state of native AztecView
if (
this.isIOS &&
event.nativeEvent.text &&
event.nativeEvent.text !== this.props.value
) {
Expand Down Expand Up @@ -615,7 +619,9 @@ export class RichText extends Component {

// update text before updating selection
// Make sure there are changes made to the content before upgrading it upward
this.onTextUpdate( event );
if ( this.isIOS ) {
this.onTextUpdate( event );
}

// Aztec can send us selection change events after it has lost focus.
// For instance the autocorrect feature will complete a partially written
Expand Down Expand Up @@ -763,7 +769,9 @@ export class RichText extends Component {
this.props.selectionEnd || 0
);
} else if ( ! isSelected && prevIsSelected ) {
this._editor.blur();
InteractionManager.runAfterInteractions( () => {
this._editor?.blur();
} );
}
}

Expand Down Expand Up @@ -998,7 +1006,7 @@ const withFormatTypes = ( WrappedComponent ) => ( props ) => {
export default compose( [
withSelect( ( select, { clientId } ) => {
const { getBlockParents, getBlock, getSettings } = select(
'core/block-editor'
blockEditorStore
);
const parents = getBlockParents( clientId, true );
const parentBlock = parents ? getBlock( parents[ 0 ] ) : undefined;
Expand Down

0 comments on commit a14915f

Please sign in to comment.