Skip to content
Snippets Groups Projects
Commit 41e24067 authored by Sofiya Tepikin's avatar Sofiya Tepikin
Browse files

Merge branch 'fix-go-back-bug' into 'master'

Fixes the error on app exiting on via the device back button

See merge request bloodyhealth/drip!291
parents e1191546 1413525e
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,7 @@ import { isSymptomView, isSettingsView } from './pages' ...@@ -14,7 +14,7 @@ import { isSymptomView, isSettingsView } from './pages'
import { headerTitles } from '../i18n/en/labels' import { headerTitles } from '../i18n/en/labels'
import setupNotifications from '../lib/notifications' import setupNotifications from '../lib/notifications'
import { getCycleDay } from '../db' import { getCycleDay, closeDb } from '../db'
class App extends Component { class App extends Component {
...@@ -30,12 +30,25 @@ class App extends Component { ...@@ -30,12 +30,25 @@ class App extends Component {
this.backHandler = BackHandler.addEventListener( this.backHandler = BackHandler.addEventListener(
'hardwareBackPress', 'hardwareBackPress',
props.goBack this.goBack
) )
setupNotifications(this.props.navigate) setupNotifications(this.props.navigate)
} }
goBack = () => {
const { currentPage } = this.props.navigation
if (currentPage === 'Home') {
closeDb()
BackHandler.exitApp()
} else {
this.props.goBack()
}
return true
}
componentWillUnmount() { componentWillUnmount() {
this.backHandler.remove() this.backHandler.remove()
} }
......
import { createSlice } from 'redux-starter-kit' import { createSlice } from 'redux-starter-kit'
import { pages, isSymptomView } from '../components/pages' import { pages, isSymptomView } from '../components/pages'
import { closeDb } from '../db'
import { BackHandler } from 'react-native'
const navigationSlice = createSlice({ const navigationSlice = createSlice({
slice: 'navigation', slice: 'navigation',
...@@ -17,12 +15,6 @@ const navigationSlice = createSlice({ ...@@ -17,12 +15,6 @@ const navigationSlice = createSlice({
}, },
goBack: ({ currentPage, previousPage }) => { goBack: ({ currentPage, previousPage }) => {
if (currentPage === 'Home') {
closeDb()
BackHandler.exitApp()
return { currentPage }
}
if (currentPage === 'CycleDay' || isSymptomView(currentPage)) { if (currentPage === 'CycleDay' || isSymptomView(currentPage)) {
if (previousPage) { if (previousPage) {
return { return {
...@@ -33,7 +25,8 @@ const navigationSlice = createSlice({ ...@@ -33,7 +25,8 @@ const navigationSlice = createSlice({
const page = pages.find(p => p.component === currentPage) const page = pages.find(p => p.component === currentPage)
return { return {
currentPage: page.parent currentPage: page.parent,
previousPage: currentPage,
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment