You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-12 22:57:38 +02:00
Improved back button handling when note has been modified
This commit is contained in:
@ -3,6 +3,7 @@ import { connect } from 'react-redux'
|
||||
import { View, Text, Button, StyleSheet, TouchableOpacity, Picker, Image } from 'react-native';
|
||||
import Icon from 'react-native-vector-icons/Ionicons';
|
||||
import { Log } from 'lib/log.js';
|
||||
import { BackButtonService } from 'lib/services/back-button.js';
|
||||
import { Menu, MenuOptions, MenuOption, MenuTrigger } from 'react-native-popup-menu';
|
||||
import { _ } from 'lib/locale.js';
|
||||
import { Setting } from 'lib/models/setting.js';
|
||||
@ -143,8 +144,9 @@ class ScreenHeaderComponent extends Component {
|
||||
this.props.dispatch({ type: 'SIDE_MENU_TOGGLE' });
|
||||
}
|
||||
|
||||
backButton_press() {
|
||||
this.props.dispatch({ type: 'NAV_BACK' });
|
||||
async backButton_press() {
|
||||
await BackButtonService.back();
|
||||
//this.props.dispatch({ type: 'NAV_BACK' });
|
||||
}
|
||||
|
||||
searchButton_press() {
|
||||
|
@ -1,11 +1,12 @@
|
||||
import React, { Component } from 'react';
|
||||
import { BackHandler, View, Button, TextInput, WebView, Text, StyleSheet, Linking, Image } from 'react-native';
|
||||
import { Keyboard, BackHandler, View, Button, TextInput, WebView, Text, StyleSheet, Linking, Image } from 'react-native';
|
||||
import { connect } from 'react-redux'
|
||||
import { uuid } from 'lib/uuid.js';
|
||||
import { Log } from 'lib/log.js'
|
||||
import { Note } from 'lib/models/note.js'
|
||||
import { Resource } from 'lib/models/resource.js'
|
||||
import { Folder } from 'lib/models/folder.js'
|
||||
import { BackButtonService } from 'lib/services/back-button.js';
|
||||
import { BaseModel } from 'lib/base-model.js'
|
||||
import { ActionButton } from 'lib/components/action-button.js';
|
||||
import Icon from 'react-native-vector-icons/Ionicons';
|
||||
@ -48,24 +49,35 @@ class NoteScreenComponent extends BaseScreenComponent {
|
||||
|
||||
this.styles_ = {};
|
||||
|
||||
// Disabled for now because it doesn't work consistently and proabably interfer with the backHandler
|
||||
// on root.js. Handling of the back button should be in one single place for this to work well.
|
||||
this.backHandler = async () => {
|
||||
if (this.isModified()) {
|
||||
let buttonId = await dialogs.pop(this, _('This note has been modified:'), [
|
||||
{ title: _('Save changes'), id: 'save' },
|
||||
{ title: _('Discard changes'), id: 'discard' },
|
||||
{ title: _('Cancel'), id: 'cancel' },
|
||||
]);
|
||||
|
||||
// this.backHandler = () => {
|
||||
// if (!this.state.note.id) {
|
||||
// return false;
|
||||
// }
|
||||
if (buttonId == 'cancel') return true;
|
||||
if (buttonId == 'save') await this.saveNoteButton_press();
|
||||
}
|
||||
|
||||
// if (this.state.mode == 'edit') {
|
||||
// this.setState({
|
||||
// note: Object.assign({}, this.state.lastSavedNote),
|
||||
// mode: 'view',
|
||||
// });
|
||||
// return true;
|
||||
// }
|
||||
if (!this.state.note.id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// return false;
|
||||
// };
|
||||
if (this.state.mode == 'edit') {
|
||||
Keyboard.dismiss()
|
||||
|
||||
this.setState({
|
||||
note: Object.assign({}, this.state.lastSavedNote),
|
||||
mode: 'view',
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
styles() {
|
||||
@ -123,7 +135,7 @@ class NoteScreenComponent extends BaseScreenComponent {
|
||||
}
|
||||
|
||||
async componentWillMount() {
|
||||
// BackHandler.addEventListener('hardwareBackPress', this.backHandler);
|
||||
BackButtonService.addHandler(this.backHandler);
|
||||
|
||||
let note = null;
|
||||
let mode = 'view';
|
||||
@ -148,7 +160,7 @@ class NoteScreenComponent extends BaseScreenComponent {
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
// BackHandler.removeEventListener('hardwareBackPress', this.backHandler);
|
||||
BackButtonService.removeHandler(this.backHandler);
|
||||
}
|
||||
|
||||
noteComponent_change(propName, propValue) {
|
||||
|
Reference in New Issue
Block a user