diff --git a/components/cycle-day/symptoms/bleeding.js b/components/cycle-day/symptoms/bleeding.js index 9d94a03cd6eab938c2d2f20f991ce7b4cb325f3c..6893bfabb1a9b085e18e686a7843b3f52711559d 100644 --- a/components/cycle-day/symptoms/bleeding.js +++ b/components/cycle-day/symptoms/bleeding.js @@ -22,7 +22,7 @@ export default class Bleeding extends SymptomView { symptomName = 'bleeding' - onBackButtonPress() { + autoSave = () => { if (typeof this.state.currentValue != 'number') { this.deleteSymptomEntry() return diff --git a/components/cycle-day/symptoms/cervix.js b/components/cycle-day/symptoms/cervix.js index f58ebf27d1cadc85a64c50a142b187d854cce49b..4515f5dd32b71d6024b89836322169c28d4dd948 100644 --- a/components/cycle-day/symptoms/cervix.js +++ b/components/cycle-day/symptoms/cervix.js @@ -19,7 +19,7 @@ export default class Cervix extends SymptomView { symptomName = 'cervix' - onBackButtonPress() { + autoSave = () => { const nothingEntered = ['opening', 'firmness', 'position'].every(val => typeof this.state[val] != 'number') if (nothingEntered) { this.deleteSymptomEntry() diff --git a/components/cycle-day/symptoms/desire.js b/components/cycle-day/symptoms/desire.js index 5ff9fadcc1f70578f345e9e63cd2d91a9d996a42..f28ff85e8a107997b4c8051505eb353f72d1a84e 100644 --- a/components/cycle-day/symptoms/desire.js +++ b/components/cycle-day/symptoms/desire.js @@ -19,7 +19,7 @@ export default class Desire extends SymptomView { symptomName = 'desire' - onBackButtonPress() { + autoSave = () => { if (typeof this.state.currentValue != 'number') { this.deleteSymptomEntry() return diff --git a/components/cycle-day/symptoms/mood.js b/components/cycle-day/symptoms/mood.js index 09f8fbcfd09cb0a07c4fe0b94b3ad7d9b3d0c4ab..6b78891d36a112876153c219fe3722851033cd02 100644 --- a/components/cycle-day/symptoms/mood.js +++ b/components/cycle-day/symptoms/mood.js @@ -24,7 +24,7 @@ export default class Mood extends SymptomView { symptomName = "mood" - onBackButtonPress() { + autoSave = () => { const nothingEntered = Object.values(this.state).every(val => !val) if (nothingEntered) { this.deleteSymptomEntry() diff --git a/components/cycle-day/symptoms/mucus.js b/components/cycle-day/symptoms/mucus.js index 2d7b9d19aa1293957a601f3094d36204b159b8d9..cc73591fe6867cefad8200939baa97f71d03ecee 100644 --- a/components/cycle-day/symptoms/mucus.js +++ b/components/cycle-day/symptoms/mucus.js @@ -20,7 +20,7 @@ export default class Mucus extends SymptomView { symptomName = 'mucus' - onBackButtonPress() { + autoSave = () => { const nothingEntered = ['feeling', 'texture'].every(val => typeof this.state[val] != 'number') if (nothingEntered) { this.deleteSymptomEntry() diff --git a/components/cycle-day/symptoms/note.js b/components/cycle-day/symptoms/note.js index c2bed812ad4a9d29d4480300e019b123490be15d..e9a2df6e287f5449be165a700f938b09af922627 100644 --- a/components/cycle-day/symptoms/note.js +++ b/components/cycle-day/symptoms/note.js @@ -23,7 +23,7 @@ export default class Note extends SymptomView { symptomName = 'note' - onBackButtonPress() { + autoSave = () => { if (!this.state.currentValue) { this.deleteSymptomEntry() return diff --git a/components/cycle-day/symptoms/pain.js b/components/cycle-day/symptoms/pain.js index 30ac355234ba30baea43154f82bcbc30d7396c1b..fdf3fec0778bb4a0fdd7c858177413e09c65028d 100644 --- a/components/cycle-day/symptoms/pain.js +++ b/components/cycle-day/symptoms/pain.js @@ -26,7 +26,7 @@ export default class Pain extends SymptomView { symptomName = 'pain' - onBackButtonPress() { + autoSave = () => { const nothingEntered = Object.values(this.state).every(val => !val) if (nothingEntered) { this.deleteSymptomEntry() diff --git a/components/cycle-day/symptoms/sex.js b/components/cycle-day/symptoms/sex.js index 9b195da75ba42aec64a568cda8195bb7ae550ab2..140afa312da91736e14094c7e28ec7dc673e9946 100644 --- a/components/cycle-day/symptoms/sex.js +++ b/components/cycle-day/symptoms/sex.js @@ -26,7 +26,7 @@ export default class Sex extends SymptomView { symptomName = "sex" - onBackButtonPress() { + autoSave = () => { const nothingEntered = Object.values(this.state).every(val => !val) if (nothingEntered) { this.deleteSymptomEntry() diff --git a/components/cycle-day/symptoms/symptom-view.js b/components/cycle-day/symptoms/symptom-view.js index 158b2e6daea636c0f7c217b94bc95cd9acb02f9f..793b8ef4f787a013ab60b0b057af1cf57c7efa95 100644 --- a/components/cycle-day/symptoms/symptom-view.js +++ b/components/cycle-day/symptoms/symptom-view.js @@ -1,6 +1,6 @@ import React, { Component } from 'react' import { - BackHandler, View, Alert, TouchableOpacity + View, Alert, TouchableOpacity } from 'react-native' import { saveSymptom } from '../../../db' import InfoPopUp from './info-symptom' @@ -13,11 +13,6 @@ import styles, { iconStyles } from '../../../styles' export default class SymptomView extends Component { constructor(props) { super() - this.backHandler = BackHandler.addEventListener( - 'hardwareBackPress', - this.handleBackButtonPressOnSymptomView.bind(this) - ) - this.globalBackhandler = props.handleBackButtonPress this.date = props.date this.navigate = props.navigate this.state = { @@ -25,6 +20,11 @@ export default class SymptomView extends Component { } } + componentDidUpdate() { + this.autoSave() + } + + // TODO where is this needed now? async handleBackButtonPressOnSymptomView() { // every specific symptom view provides their own onBackButtonPress method const stopHere = await this.onBackButtonPress() @@ -39,10 +39,6 @@ export default class SymptomView extends Component { saveSymptom(this.symptomName, this.date) } - componentWillUnmount() { - this.backHandler.remove() - } - isDeleteIconActive() { const symptomValueHasBeenFilledOut = key => { // the state tracks whether the symptom info should be shown, @@ -63,6 +59,7 @@ export default class SymptomView extends Component { <Header title={headerTitles[this.symptomName].toLowerCase()} date={this.date} + // TODO what to put here instead? goBack={this.handleBackButtonPressOnSymptomView.bind(this)} deleteIconActive={this.isDeleteIconActive()} deleteEntry={() => {