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

[FIX] rich text focus loop #19240

Merged
merged 5 commits into from
Jan 7, 2020
Merged
Changes from all commits
Commits
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
17 changes: 15 additions & 2 deletions packages/rich-text/src/component/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,11 @@ export class RichText extends Component {
onBlur( event ) {
this.isTouched = false;

// Check if value is up to date with latest state of native AztecView
if ( event.nativeEvent.text && event.nativeEvent.text !== this.props.value ) {
this.onTextUpdate( event );
}

if ( this.props.onBlur ) {
this.props.onBlur( event );
}
Expand Down Expand Up @@ -457,8 +462,16 @@ export class RichText extends Component {
// Make sure there are changes made to the content before upgrading it upward
this.onTextUpdate( event );

this.onSelectionChange( realStart, realEnd );

// Aztec can send us selection change events after it has lost focus.
// For instance the autocorrect feature will complete a partially written
// word when resigning focus, causing a selection change event.
// Forwarding this selection change could cause this RichText to regain
// focus and start a focus loop.
//
// See https://github.com/wordpress-mobile/gutenberg-mobile/issues/1696
if ( this.props.__unstableIsSelected ) {
this.onSelectionChange( realStart, realEnd );
}
// Update lastEventCount to prevent Aztec from re-rendering the content it just sent
this.lastEventCount = event.nativeEvent.eventCount;

Expand Down