diff --git a/app.js b/app.js
index 2cfc07e..b6e9ff5 100644
--- a/app.js
+++ b/app.js
@@ -1,11 +1,11 @@
import React, { Component } from 'react'
-import { View, BackHandler } from 'react-native'
+import { View, BackHandler, ScrollView } from 'react-native'
import Header from './components/header'
import Menu from './components/menu'
import Home from './components/home'
import Calendar from './components/calendar'
import CycleDay from './components/cycle-day/cycle-day-overview'
-import SymptomView from './components/cycle-day/symptoms'
+import symptomViews from './components/cycle-day/symptoms'
import Chart from './components/chart/chart'
import Settings from './components/settings'
import Stats from './components/stats'
@@ -13,8 +13,11 @@ import Stats from './components/stats'
// this is until react native fixes this bugg, see
// https://github.com/facebook/react-native/issues/18868#issuecomment-382671739
import { YellowBox } from 'react-native'
+import ActionButtonFooter from './components/cycle-day/symptoms/action-button-footer';
YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated'])
+const isSymptomView = name => Object.keys(symptomViews).indexOf(name) > -1
+
export default class App extends Component {
constructor(props) {
super(props)
@@ -24,9 +27,11 @@ export default class App extends Component {
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')
+ if (isSymptomView(this.state.currentPage)) {
+ this.navigate('CycleDay', {cycleDay: this.state.currentProps.cycleDay})
+ } else {
+ this.navigate('Home')
+ }
return true
}.bind(this)
@@ -41,34 +46,40 @@ export default class App extends Component {
this.setState({currentPage: pageName, currentProps: props})
}
+ setActionButtonState(actionButtonInfo) {
+ this.setState({actionButtonInfo})
+ }
+
+ unsetActionButtonState() {
+ this.setState({actionButtonInfo: null})
+ }
+
render() {
+ const page = {
+ Home, Calendar, CycleDay, Chart, Settings, Stats, ...symptomViews
+ }[this.state.currentPage]
return (
{this.state.currentPage != 'CycleDay' && }
-
-
-
+
+ {React.createElement(page, {
+ navigate: this.navigate.bind(this),
+ setActionButtonState: this.setActionButtonState.bind(this),
+ unsetActionButtonState: this.unsetActionButtonState.bind(this),
+ ...this.state.currentProps
+ })}
+
-
+ {isSymptomView(this.state.currentPage) && this.state.actionButtonInfo ?
+
+ :
+
)
}
-}
-
-class CurrentPage extends Component {
- render () {
- const page = {
- Home, Calendar, CycleDay, SymptomView, Chart, Settings, Stats
- }[this.props.page]
- const props = this.props.props || {}
- return React.createElement(page, {
- navigate: this.props.navigate,
- ...props
- })
- }
}
\ No newline at end of file
diff --git a/components/cycle-day/action-buttons.js b/components/cycle-day/action-buttons.js
deleted file mode 100644
index 0a6b0a0..0000000
--- a/components/cycle-day/action-buttons.js
+++ /dev/null
@@ -1,47 +0,0 @@
-import React from 'react'
-import {
- View,
- Button,
-} from 'react-native'
-import { saveSymptom } from '../../db'
-
-export default function (navigateToOverView) {
- return function ({ symptom, cycleDay, saveAction, saveDisabled}) {
- const buttons = [
- {
- title: 'Cancel',
- action: () => navigateToOverView()
- },
- {
- title: 'Delete',
- action: () => {
- saveSymptom(symptom, cycleDay)
- navigateToOverView()
- },
- disabledCondition: !cycleDay[symptom]
- }, {
- title: 'Save',
- action: () => {
- saveAction()
- navigateToOverView()
- },
- disabledCondition: saveDisabled
- }
- ]
-
- return buttons.map(({ title, action, disabledCondition }, i) => {
- const style = { flex: 1, marginHorizontal: 10 }
- if (i === 0) style.marginLeft = 0
- if (i === buttons.length - 1) style.marginRight = 0
- return (
-
-
-
- )
- })
- }
-}
\ No newline at end of file
diff --git a/components/cycle-day/cycle-day-overview.js b/components/cycle-day/cycle-day-overview.js
index 0076aa2..9ab3225 100644
--- a/components/cycle-day/cycle-day-overview.js
+++ b/components/cycle-day/cycle-day-overview.js
@@ -40,9 +40,8 @@ export default class CycleDayOverView extends Component {
}
navigate(symptom) {
- this.props.navigate('SymptomView', {
- symptom,
- cycleDay: this.state.cycleDay
+ this.props.navigate(symptom, {
+ cycleDay: this.state.cycleDay,
})
}
diff --git a/components/cycle-day/symptoms/action-button-footer.js b/components/cycle-day/symptoms/action-button-footer.js
index 0f05a7b..be0cd6a 100644
--- a/components/cycle-day/symptoms/action-button-footer.js
+++ b/components/cycle-day/symptoms/action-button-footer.js
@@ -1,19 +1,20 @@
import React, { Component } from 'react'
import {
- View,
- Button,
+ View, TouchableOpacity, Text
} from 'react-native'
+import Icon from 'react-native-vector-icons/MaterialCommunityIcons'
import { saveSymptom } from '../../../db'
-import styles from '../../../styles'
+import styles, {iconStyles} from '../../../styles'
export default class ActionButtonFooter extends Component {
render() {
const { symptom, cycleDay, saveAction, saveDisabled, navigate} = this.props
- const navigateToOverView = () => navigate('CycleDay', cycleDay)
+ const navigateToOverView = () => navigate('CycleDay', {cycleDay})
const buttons = [
{
title: 'Cancel',
- action: () => navigateToOverView()
+ action: () => navigateToOverView(),
+ icon: 'cancel'
},
{
title: 'Delete',
@@ -21,31 +22,34 @@ export default class ActionButtonFooter extends Component {
saveSymptom(symptom, cycleDay)
navigateToOverView()
},
- disabledCondition: !cycleDay[symptom]
+ disabledCondition: !cycleDay[symptom],
+ icon: 'delete-outline'
}, {
title: 'Save',
action: () => {
saveAction()
navigateToOverView()
},
- disabledCondition: saveDisabled
+ disabledCondition: saveDisabled,
+ icon: 'content-save-outline'
}
]
return (
-
- {buttons.map(({ title, action, disabledCondition }, i) => {
- const style = { flex: 1, marginHorizontal: 10 }
- if (i === 0) style.marginLeft = 0
- if (i === buttons.length - 1) style.marginRight = 0
+
+ {buttons.map(({ title, action, disabledCondition, icon }, i) => {
return (
-
-
-
+
+
+
+ {title}
+
+
)
})}
diff --git a/components/cycle-day/symptoms/index.js b/components/cycle-day/symptoms/index.js
index 4ce4010..12622b7 100644
--- a/components/cycle-day/symptoms/index.js
+++ b/components/cycle-day/symptoms/index.js
@@ -1,7 +1,3 @@
-import React, { Component } from 'react'
-import { ScrollView, BackHandler } from 'react-native'
-import Header from '../../header'
-import actionButtonModule from '../action-buttons'
import BleedingEditView from './bleeding'
import TemperatureEditView from './temperature'
import MucusEditView from './mucus'
@@ -10,7 +6,7 @@ import NoteEditView from './note'
import DesireEditView from './desire'
import SexEditView from './sex'
-const symptomViews = {
+export default {
BleedingEditView,
TemperatureEditView,
MucusEditView,
@@ -18,54 +14,4 @@ const symptomViews = {
NoteEditView,
DesireEditView,
SexEditView
-}
-const titles = {
- BleedingEditView: 'Bleeding',
- TemperatureEditView: 'Temperature',
- MucusEditView: 'Mucus',
- CervixEditView: 'Cervix',
- NoteEditView: 'Note',
- DesireEditView: 'Desire',
- SexEditView: 'Sex'
-}
-
-export default class SymptomView extends Component {
- constructor(props) {
- super(props)
-
- this.state = {
- visibleComponent: props.symptom,
- cycleDay: props.cycleDay
- }
-
- this.makeActionButtons = actionButtonModule(() => {
- 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() {
- return (
-
-
- {React.createElement(
- symptomViews[this.state.visibleComponent],
- {
- cycleDay: this.state.cycleDay,
- makeActionButtons: this.makeActionButtons
- }
- )}
-
- )
- }
-}
+}
\ No newline at end of file
diff --git a/components/cycle-day/symptoms/temperature.js b/components/cycle-day/symptoms/temperature.js
index 7296883..a7bd55e 100644
--- a/components/cycle-day/symptoms/temperature.js
+++ b/components/cycle-day/symptoms/temperature.js
@@ -4,7 +4,7 @@ import {
Text,
TextInput,
Switch,
- Keyboard
+ Keyboard,
} from 'react-native'
import DateTimePicker from 'react-native-modal-datetime-picker-nevo'
@@ -37,10 +37,27 @@ export default class Temp extends Component {
time: this.time || LocalTime.now().truncatedTo(MINUTES).toString(),
isTimePickerVisible: false
}
+
+ props.setActionButtonState({
+ symptom : 'temperature',
+ cycleDay: props.cycleDay,
+ saveAction: () => {
+ const dataToSave = {
+ value: Number(this.state.currentValue),
+ exclude: this.state.exclude,
+ time: this.state.time
+ }
+ saveSymptom('temperature', props.cycleDay, dataToSave)
+ },
+ saveDisabled: this.state.currentValue === '' || isInvalidTime(this.state.time)
+ })
+ }
+
+ componentWillUnmount() {
+ this.props.unsetActionButtonState()
}
render() {
- const cycleDay = this.cycleDay
return (
@@ -61,7 +78,7 @@ export default class Temp extends Component {
style={styles.temperatureTextInput}
onFocus={() => {
Keyboard.dismiss()
- this.setState({isTimePickerVisible: true})
+ this.setState({ isTimePickerVisible: true })
}}
value={this.state.time}
/>
@@ -75,7 +92,7 @@ export default class Temp extends Component {
isTimePickerVisible: false
})
}}
- onCancel={() => this.setState({isTimePickerVisible: false})}
+ onCancel={() => this.setState({ isTimePickerVisible: false })}
/>
Exclude
@@ -86,21 +103,6 @@ export default class Temp extends Component {
value={this.state.exclude}
/>
-
- {this.makeActionButtons({
- symptom: 'temperature',
- cycleDay: this.cycleDay,
- saveAction: () => {
- const dataToSave = {
- value: Number(this.state.currentValue),
- exclude: this.state.exclude,
- time: this.state.time
- }
- saveSymptom('temperature', cycleDay, dataToSave)
- },
- saveDisabled: this.state.currentValue === '' || isInvalidTime(this.state.time)
- })}
-
)
}
diff --git a/components/menu.js b/components/menu.js
index 1a8bed7..8a55187 100644
--- a/components/menu.js
+++ b/components/menu.js
@@ -8,11 +8,12 @@ import styles, { iconStyles } from '../styles'
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'
export default class Menu extends Component {
- makeMenuItem({ title, icon, componentName }) {
+ makeMenuItem({ title, icon, onPress}, i) {
return (
this.props.navigate(componentName)}
+ onPress={onPress}
style={styles.menuItem}
+ key={i.toString()}
>
@@ -21,20 +22,22 @@ export default class Menu extends Component {
)
}
+
+ goTo(componentName) {
+ this.props.navigate(componentName)
+ }
+
render() {
return (
- this.props.symptomView ?
- placeActionButtons()
- :
-
- {[
- {title: 'Home', icon: 'home', componentName: 'Home'},
- {title: 'Calendar', icon: 'calendar-range', componentName: 'Calendar'},
- {title: 'Chart', icon: 'chart-line', componentName: 'Chart'},
- {title: 'Stats', icon: 'chart-pie', componentName: 'Stats'},
- {title: 'Settings', icon: 'settings', componentName: 'Settings'},
- ].map(this.makeMenuItem.bind(this))}
-
+
+ {[
+ { title: 'Home', icon: 'home', onPress: () => this.goTo('Home') },
+ { title: 'Calendar', icon: 'calendar-range', onPress: () => this.goTo('Calendar') },
+ { title: 'Chart', icon: 'chart-line', onPress: () => this.goTo('Chart') },
+ { title: 'Stats', icon: 'chart-pie', onPress: () => this.goTo('Stats') },
+ { title: 'Settings', icon: 'settings', onPress: () => this.goTo('Settings') },
+ ].map(this.makeMenuItem.bind(this))}
+
)
}
}