Skip to content
This repository has been archived by the owner on Jun 15, 2022. It is now read-only.

Commit

Permalink
Android locked notes don't disable textview, update text state if not…
Browse files Browse the repository at this point in the history
…e is coming from retrieved
  • Loading branch information
moughxyz committed Feb 1, 2019
1 parent 562be57 commit befbf64
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/screens/Compose.js
Expand Up @@ -63,7 +63,10 @@ export default class Compose extends Abstract {

registerObservers() {
this.syncObserver = Sync.get().addEventHandler((event, data) => {

if(event == "sync:completed") {
let isInRetrieved = data.retrievedItems && data.retrievedItems.map((i) => i.uuid).includes(this.note.uuid);
let isInSaved = data.savedItems && data.savedItems.map((i) => i.uuid).includes(this.note.uuid);
if(this.note.deleted || this.note.content.trashed) {
let clearNote = this.note.deleted == true;
// if Trashed, and we're in the Trash view, don't clear note.
Expand All @@ -80,7 +83,7 @@ export default class Compose extends Abstract {
this.props.navigation.closeRightDrawer();
this.setNote(null);
}
} else if(data.retrievedItems && this.note.uuid && data.retrievedItems.concat(data.savedItems).map((i) => i.uuid).includes(this.note.uuid)) {
} else if(this.note.uuid && (isInRetrieved || isInSaved)) {
/*
You have to be careful about when you render inside this component. Rendering with the native SNTextView component
can cause the cursor to go to the end of the input, both on iOS and Android. We want to force an update only if retrievedItems includes this item
Expand All @@ -94,9 +97,16 @@ export default class Compose extends Abstract {
Do not make text part of the state, otherwise that would cause a re-render on every keystroke.
*/

let newState = {title: this.note.title, noteLocked: this.note.locked ? true : false};

// only include `text` if this item is coming back from retrieved, as this will cause text view cursor to reset to top
if(isInRetrieved) {
newState.text = this.note.text;
}

// 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});
this.setState(newState);
}
}
});
Expand Down Expand Up @@ -320,7 +330,11 @@ export default class Compose extends Abstract {

onTextChange = (text) => {
if(this.note.locked) {
// On Android, we don't disable the text view if the note is locked, as that also disables selection.
Alert.alert('Note Locked', "This note is locked. Please unlock this note to make changes.", [{text: 'OK'}])
// For some reason, tested on Android, calling forceUpdate here with the intention of re-rendering the note's original text
// does not render the original text, but keeps the pending edits we have.
// this.forceUpdate();
return;
}

Expand Down Expand Up @@ -496,7 +510,6 @@ export default class Compose extends Abstract {
selectionColor={StyleKit.lighten(StyleKit.variable("stylekitInfoColor"), 0.35)}
handlesColor={StyleKit.variable("stylekitInfoColor")}
onChangeText={this.onTextChange}
editable={!this.note.locked}
/>
</View>
}
Expand Down

0 comments on commit befbf64

Please sign in to comment.