Handle back button presses

This commit is contained in:
Julia Friesel
2018-08-19 16:11:01 +02:00
parent 86f26e3814
commit a67bfda43f
3 changed files with 30 additions and 7 deletions
+15 -1
View File
@@ -1,5 +1,5 @@
import React, { Component } from 'react'
import { View } from 'react-native'
import { View, BackHandler } from 'react-native'
import Header from './components/header'
import Menu from './components/menu'
import Home from './components/home'
@@ -21,6 +21,20 @@ export default class App extends Component {
this.state = {
currentPage: 'Home'
}
const handleBackButtonPress = function() {
if (this.state.currentPage === 'Home') return false
// this is handled in the SymptomView
if (this.state.currentPage === 'SymptomView') return true
this.navigate('Home')
return true
}.bind(this)
this.backHandler = BackHandler.addEventListener('hardwareBackPress', handleBackButtonPress)
}
componentWillUnmount() {
this.backHandler.remove()
}
navigate(pageName, props) {