Await alert result before navigating back

This commit is contained in:
Julia Friesel
2019-05-14 13:37:35 +02:00
parent 37564621e0
commit f022fb6b8a
2 changed files with 37 additions and 22 deletions
+11 -6
View File
@@ -7,12 +7,20 @@ import { headerTitles } from '../../../i18n/en/labels'
export default class SymptomView extends Component {
constructor(props) {
super()
// every specific symptom view provides their own onBackButtonPress method
this.backHandler = BackHandler.addEventListener('hardwareBackPress', this.onBackButtonPress.bind(this))
this.backHandler = BackHandler.addEventListener(
'hardwareBackPress',
this.handleBackButtonPressOnSymptomView.bind(this)
)
this.globalBackhandler = props.handleBackButtonPress
this.date = props.date
}
async handleBackButtonPressOnSymptomView() {
// every specific symptom view provides their own onBackButtonPress method
const stopHere = await this.onBackButtonPress()
if (!stopHere) this.globalBackhandler()
}
saveSymptomEntry(entry) {
saveSymptom(this.symptomName, this.date, entry)
}
@@ -31,10 +39,7 @@ export default class SymptomView extends Component {
<Header
title={headerTitles[this.symptomName].toLowerCase()}
date={this.date}
goBack={() => {
this.onBackButtonPress()
this.globalBackhandler()
}}
goBack={this.handleBackButtonPressOnSymptomView.bind(this)}
deleteEntry={() => {
this.deleteSymptomEntry()
this.globalBackhandler()