diff --git a/app.js b/app.js index ec6f30871e87d6f8ef923284849d990ed722002a..2cfc07e746f97001ae8d7cc5d4a2ff13dd5e2eff 100644 --- a/app.js +++ b/app.js @@ -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) { diff --git a/components/calendar.js b/components/calendar.js index 3159b0c1370396784c35930e3d60edb6cfa17bea..074487297ff8462b59297bf840e1990a3480a4d5 100644 --- a/components/calendar.js +++ b/components/calendar.js @@ -10,7 +10,6 @@ export default class CalendarView extends Component { this.state = { bleedingDaysInCalFormat: toCalFormat(bleedingDaysSortedByDate) } - console.log(Object.keys(this.state.bleedingDaysInCalFormat)) this.setStateWithCalFormattedDays = (function (CalendarComponent) { return function(_, changes) { @@ -35,7 +34,6 @@ export default class CalendarView extends Component { } render() { - console.log('cal render') return ( <View> <View style={styles.container}> diff --git a/components/cycle-day/symptoms/index.js b/components/cycle-day/symptoms/index.js index 5b73d857ca87914c15e4bbea99b753bbf8eac9a7..4ce40106de45c3334885aa0f40eb02c8b0e6a7f9 100644 --- a/components/cycle-day/symptoms/index.js +++ b/components/cycle-day/symptoms/index.js @@ -1,5 +1,5 @@ import React, { Component } from 'react' -import { ScrollView } from 'react-native' +import { ScrollView, BackHandler } from 'react-native' import Header from '../../header' import actionButtonModule from '../action-buttons' import BleedingEditView from './bleeding' @@ -34,13 +34,24 @@ export default class SymptomView extends Component { super(props) this.state = { - visibleComponent: props.navigation.state.params.symptom, - cycleDay: props.navigation.state.params.cycleDay + visibleComponent: props.symptom, + cycleDay: props.cycleDay } this.makeActionButtons = actionButtonModule(() => { - this.props.navigation.navigate('CycleDay', {cycleDay: this.state.cycleDay}) + this.props.navigate('CycleDay', {cycleDay: this.state.cycleDay}) }) + + const handleBackButtonPress = function() { + this.props.navigate('CycleDay', {cycleDay: this.state.cycleDay}) + return true + }.bind(this) + + this.backHandler = BackHandler.addEventListener('hardwareBackPress', handleBackButtonPress) + } + + componentWillUnmount() { + this.backHandler.remove() } render() {