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

[RNMobile] Make sure the native side is refreshed after blocks Merging #11576

Merged
merged 4 commits into from
Nov 8, 2018
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
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