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
This commit is contained in:
Sofiya Tepikin
2020-04-26 15:25:40 +00:00
2 changed files with 17 additions and 11 deletions
+15 -2
View File
@@ -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()
}