1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Android: Fixes #53: Back button should exit app if nothing to go back to

This commit is contained in:
Laurent Cozic 2017-12-01 19:44:34 +00:00
parent c72e0a14c0
commit 818537933a

View File

@ -1,5 +1,5 @@
const React = require('react'); const Component = React.Component;
const { Keyboard, NativeModules } = require('react-native');
const { Keyboard, NativeModules, BackHandler } = require('react-native');
const { connect, Provider } = require('react-redux');
const { BackButtonService } = require('lib/services/back-button.js');
const AlarmService = require('lib/services/AlarmService.js');
@ -255,7 +255,7 @@ const appReducer = (state = appDefaultState, action) => {
let store = createStore(appReducer, applyMiddleware(generalMiddleware));
async function initialize(dispatch, backButtonHandler) {
async function initialize(dispatch) {
shimInit();
Setting.setConstant('env', __DEV__ ? 'dev' : 'prod');
@ -372,8 +372,6 @@ async function initialize(dispatch, backButtonHandler) {
reg.logger().error('Initialization error:', error);
}
BackButtonService.initialize(backButtonHandler);
reg.setupRecurrentSync();
PoorManIntervals.setTimeout(() => {
@ -394,6 +392,10 @@ class AppComponent extends React.Component {
constructor() {
super();
this.lastSyncStarted_ = defaultState.syncStarted;
this.backButtonHandler_ = () => {
return this.backButtonHandler();
}
}
async componentDidMount() {
@ -403,7 +405,7 @@ class AppComponent extends React.Component {
state: 'initializing',
});
await initialize(this.props.dispatch, this.backButtonHandler.bind(this));
await initialize(this.props.dispatch);
this.props.dispatch({
type: 'APP_STATE_SET',
@ -411,6 +413,8 @@ class AppComponent extends React.Component {
});
}
BackButtonService.initialize(this.backButtonHandler_);
AlarmService.setInAppNotificationHandler(async (alarmId) => {
const alarm = await Alarm.load(alarmId);
const notification = await Alarm.makeNotification(alarm);
@ -434,6 +438,8 @@ class AppComponent extends React.Component {
return true;
}
BackHandler.exitApp();
return false;
}