From 7e41eaa8458c866618d418c12fe4e0dfd4d56737 Mon Sep 17 00:00:00 2001 From: Dratwas Date: Thu, 19 Dec 2019 14:55:23 +0100 Subject: [PATCH 1/5] check if onBlur event contains text that is different than value --- packages/rich-text/src/component/index.native.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/rich-text/src/component/index.native.js b/packages/rich-text/src/component/index.native.js index 4176b0d20fc3af..cf1a7873ae7f7c 100644 --- a/packages/rich-text/src/component/index.native.js +++ b/packages/rich-text/src/component/index.native.js @@ -411,6 +411,10 @@ export class RichText extends Component { onBlur( event ) { this.isTouched = false; + if ( event.nativeEvent.text !== this.props.value ) { + this.onTextUpdate( event ); + } + if ( this.props.onBlur ) { this.props.onBlur( event ); } From 0856422c4b04c3bf01d99448d5f5219d97ec4e53 Mon Sep 17 00:00:00 2001 From: Dratwas Date: Thu, 19 Dec 2019 17:32:18 +0100 Subject: [PATCH 2/5] add check if there is a text in native event --- packages/rich-text/src/component/index.native.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/rich-text/src/component/index.native.js b/packages/rich-text/src/component/index.native.js index cf1a7873ae7f7c..ea5f8083994d83 100644 --- a/packages/rich-text/src/component/index.native.js +++ b/packages/rich-text/src/component/index.native.js @@ -411,7 +411,8 @@ export class RichText extends Component { onBlur( event ) { this.isTouched = false; - if ( event.nativeEvent.text !== this.props.value ) { + // 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 ); } From dadda25868cb32b0b4fdab7cc9748a00fa09c199 Mon Sep 17 00:00:00 2001 From: Jorge Bernal Date: Thu, 19 Dec 2019 09:46:55 +0100 Subject: [PATCH 3/5] Prevent re-selection of RichText when native selection changes as a result of resigning focus --- packages/rich-text/src/component/index.native.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/rich-text/src/component/index.native.js b/packages/rich-text/src/component/index.native.js index ea5f8083994d83..9736fc47adba37 100644 --- a/packages/rich-text/src/component/index.native.js +++ b/packages/rich-text/src/component/index.native.js @@ -440,7 +440,16 @@ export class RichText extends Component { this.setState( { activeFormats } ); } - this.props.onSelectionChange( start, end ); + // Aztec can send us selection change events after it has lost focus. + // For instance the autocorrect feature will complete a partially written + // word when resiging 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.props.onSelectionChange( start, end ); + } } onSelectionChangeFromAztec( start, end, text, event ) { From a22b64d04d59a2dbe03bdf570f04883a2960ae2e Mon Sep 17 00:00:00 2001 From: Jorge Bernal Date: Thu, 19 Dec 2019 09:49:43 +0100 Subject: [PATCH 4/5] Fix typo --- packages/rich-text/src/component/index.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rich-text/src/component/index.native.js b/packages/rich-text/src/component/index.native.js index 9736fc47adba37..6ea4097fd42c72 100644 --- a/packages/rich-text/src/component/index.native.js +++ b/packages/rich-text/src/component/index.native.js @@ -442,7 +442,7 @@ export class RichText extends Component { // Aztec can send us selection change events after it has lost focus. // For instance the autocorrect feature will complete a partially written - // word when resiging focus, causing a selection change event. + // 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. // From 38ec2eb72e2b43bcb83da66e3ea540bebd84f0a6 Mon Sep 17 00:00:00 2001 From: Dratwas Date: Fri, 20 Dec 2019 16:05:44 +0100 Subject: [PATCH 5/5] Check if isSelected only in onSelectionChangeFromAztec --- .../rich-text/src/component/index.native.js | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/rich-text/src/component/index.native.js b/packages/rich-text/src/component/index.native.js index 6ea4097fd42c72..c268951a091a83 100644 --- a/packages/rich-text/src/component/index.native.js +++ b/packages/rich-text/src/component/index.native.js @@ -440,16 +440,7 @@ export class RichText extends Component { this.setState( { activeFormats } ); } - // 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.props.onSelectionChange( start, end ); - } + this.props.onSelectionChange( start, end ); } onSelectionChangeFromAztec( start, end, text, event ) { @@ -471,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;