From dd26cfe19b7ac80cfe702396c2d931078bb68a47 Mon Sep 17 00:00:00 2001 From: Mo Bitar Date: Wed, 23 Jan 2019 13:25:58 -0600 Subject: [PATCH] Fix issue where render may be called due to unnecessary state change --- src/screens/Compose.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/screens/Compose.js b/src/screens/Compose.js index fe4036dc..93ccd50e 100644 --- a/src/screens/Compose.js +++ b/src/screens/Compose.js @@ -50,7 +50,9 @@ export default class Compose extends Abstract { if(noteId) { note = ModelManager.get().findItem(noteId);} this.setNote(note, true); - this.constructState({title: this.note.title, noteLocked: this.note.locked /* required to re-render on change */}); + // Use true/false for note.locked as we don't want values of null or undefined, which may cause + // unnecessary renders. + this.constructState({title: this.note.title, noteLocked: this.note.locked ? true : false /* required to re-render on change */}); this.configureHeaderBar(); @@ -91,7 +93,10 @@ export default class Compose extends Abstract { Do not make text part of the state, otherwise that would cause a re-render on every keystroke. */ - this.setState({title: this.note.title, noteLocked: this.note.locked}); + + // Use true/false for note.locked as we don't want values of null or undefined, which may cause + // unnecessary renders. (on constructor it was undefined, and here, it was null, causing a re-render to occur on android, causing textview to reset cursor) + this.setState({title: this.note.title, noteLocked: this.note.locked ? true : false}); } } });