diff --git a/components/app.js b/components/app.js index 6ae3e8602c78007f653be12c83f2274e24f98ba6..37ba5c5a3e3e821345bdf79a26ede649706887b5 100644 --- a/components/app.js +++ b/components/app.js @@ -14,7 +14,7 @@ import { isSymptomView, isSettingsView } from './pages' import { headerTitles } from '../i18n/en/labels' import setupNotifications from '../lib/notifications' -import { getCycleDay } from '../db' +import { getCycleDay, closeDb } from '../db' class App extends Component { @@ -30,12 +30,25 @@ class App extends Component { this.backHandler = BackHandler.addEventListener( 'hardwareBackPress', - props.goBack + this.goBack ) setupNotifications(this.props.navigate) } + goBack = () => { + const { currentPage } = this.props.navigation + + if (currentPage === 'Home') { + closeDb() + BackHandler.exitApp() + } else { + this.props.goBack() + } + + return true + } + componentWillUnmount() { this.backHandler.remove() } diff --git a/slices/navigation.js b/slices/navigation.js index 24991df9a3d7bdbd1cefd05905352e6298dfca3a..89a442c5c4039f44ab53c6f22840d341d5f842b8 100644 --- a/slices/navigation.js +++ b/slices/navigation.js @@ -1,7 +1,5 @@ import { createSlice } from 'redux-starter-kit' import { pages, isSymptomView } from '../components/pages' -import { closeDb } from '../db' -import { BackHandler } from 'react-native' const navigationSlice = createSlice({ slice: 'navigation', @@ -17,12 +15,6 @@ const navigationSlice = createSlice({ }, goBack: ({ currentPage, previousPage }) => { - if (currentPage === 'Home') { - closeDb() - BackHandler.exitApp() - return { currentPage } - } - if (currentPage === 'CycleDay' || isSymptomView(currentPage)) { if (previousPage) { return { @@ -33,7 +25,8 @@ const navigationSlice = createSlice({ const page = pages.find(p => p.component === currentPage) return { - currentPage: page.parent + currentPage: page.parent, + previousPage: currentPage, } } }