Skip to content

Commit

Permalink
[RNMobile] Make sure the native side is refreshed after blocks Merging (
Browse files Browse the repository at this point in the history
#11576)

* Make sure the new content is correctly propagated to the native side after merge.

* Fix lint
  • Loading branch information
daniloercoli authored Nov 8, 2018
1 parent 5728b36 commit 996f0fe
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions packages/editor/src/components/rich-text/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,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 );
}

Expand Down Expand Up @@ -274,14 +268,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;
}

Expand Down

0 comments on commit 996f0fe

Please sign in to comment.