From 720060fc366a65250988597f13b0a2eae6dee99b Mon Sep 17 00:00:00 2001 From: Danilo Ercoli Date: Wed, 7 Nov 2018 12:26:51 +0100 Subject: [PATCH 1/2] Make sure the new content is correctly propagated to the native side after merge. --- .../src/components/rich-text/index.native.js | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/editor/src/components/rich-text/index.native.js b/packages/editor/src/components/rich-text/index.native.js index c0fb04867bde45..0dd4fe9c5db714 100644 --- a/packages/editor/src/components/rich-text/index.native.js +++ b/packages/editor/src/components/rich-text/index.native.js @@ -220,12 +220,6 @@ export class RichText extends Component { const empty = this.isEmpty(); if ( onMerge ) { - // The onMerge event can cause a content update event for this block. Such event should - // definitely be processed by our native components, since they have no knowledge of - // how the split works. Setting lastEventCount to undefined forces the native component to - // always update when provided with new content. - this.lastEventCount = undefined; - onMerge( ! isReverse ); } @@ -273,14 +267,23 @@ export class RichText extends Component { this.lastContent = undefined; return true; } - // The check below allows us to avoid updating the content right after an `onChange` call - // first time the component is drawn with empty content `lastContent` is undefined - if ( nextProps.value && + // The check below allows us to avoid updating the content right after an `onChange` call. + // The first time the component is drawn `lastContent` and `lastEventCount ` are both undefined + if ( this.lastEventCount && + nextProps.value && this.lastContent && - this.lastEventCount ) { + nextProps.value === this.lastContent) { return false; } + // If the component is changed React side (merging/splitting/custom text actions) we need to make sure + // the native is updated as well + if ( nextProps.value && + this.lastContent && + nextProps.value !== this.lastContent) { + this.lastEventCount = undefined; // force a refresh on the native side + } + return true; } From 65b483177460973b1fba63129b0d42f33e8947ad Mon Sep 17 00:00:00 2001 From: Danilo Ercoli Date: Wed, 7 Nov 2018 12:44:23 +0100 Subject: [PATCH 2/2] Fix lint --- packages/editor/src/components/rich-text/index.native.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/editor/src/components/rich-text/index.native.js b/packages/editor/src/components/rich-text/index.native.js index 0dd4fe9c5db714..1c753b9c34d7a4 100644 --- a/packages/editor/src/components/rich-text/index.native.js +++ b/packages/editor/src/components/rich-text/index.native.js @@ -269,18 +269,18 @@ export class RichText extends Component { } // The check below allows us to avoid updating the content right after an `onChange` call. // The first time the component is drawn `lastContent` and `lastEventCount ` are both undefined - if ( this.lastEventCount && + if ( this.lastEventCount && nextProps.value && this.lastContent && - nextProps.value === this.lastContent) { + nextProps.value === this.lastContent ) { return false; } - // If the component is changed React side (merging/splitting/custom text actions) we need to make sure + // If the component is changed React side (merging/splitting/custom text actions) we need to make sure // the native is updated as well if ( nextProps.value && this.lastContent && - nextProps.value !== this.lastContent) { + nextProps.value !== this.lastContent ) { this.lastEventCount = undefined; // force a refresh on the native side }