diff --git a/components/home.js b/components/home.js
index 1d66b53..112094c 100644
--- a/components/home.js
+++ b/components/home.js
@@ -1,4 +1,5 @@
import React, { Component } from 'react'
+import { Linking } from 'react-native'
import { ScrollView, View, TouchableOpacity, TouchableHighlight, Dimensions } from 'react-native'
import { LocalDate, ChronoUnit } from 'js-joda'
import Icon from 'react-native-vector-icons/Entypo'
@@ -12,16 +13,63 @@ import AppText, { AppTextLight } from './app-text'
import DripHomeIcon from '../assets/drip-home-icons'
import Button from './button'
+const ShowMoreToggler = ({ isShowingMore, onToggle }) => {
+ const {height, width} = Dimensions.get('window')
+ const leftPosition = isShowingMore ? 10 : width - 40
+ const style = isShowingMore ? styles.showLess : styles.showMore
+ const topPosition = height / 2 - styles.header.height - 30
+
+ return (
+
+
+ {isShowingMore ? shared.less : shared.more}
+
+
+
+ )
+}
+
+const IconText = ({ children, wrapperStyles }) => {
+ return (
+
+
+ { children }
+
+
+ )
+}
+
+const HomeElement = ({ children, onPress, buttonColor, buttonLabel }) => {
+ return (
+
+ { children }
+
+
+ )
+}
+
export default class Home extends Component {
constructor(props) {
super(props)
- this.getCycleDayNumber = cycleModule().getCycleDayNumber
- this.getBleedingPrediction = cycleModule().getPredictedMenses
+ const { getCycleDayNumber, getPredictedMenses } = cycleModule()
+ this.getCycleDayNumber = getCycleDayNumber
+ this.getBleedingPrediction = getPredictedMenses
this.todayDateString = LocalDate.now().toString()
const prediction = this.getBleedingPrediction()
const fertilityStatus = getFertilityStatusForDay(this.todayDateString)
this.state = {
+ isShowingMore: false,
cycleDayNumber: this.getCycleDayNumber(this.todayDateString),
predictionText: determinePredictionText(prediction),
bleedingPredictionRange: getBleedingPredictionRange(prediction),
@@ -32,141 +80,91 @@ export default class Home extends Component {
}
passTodayTo(componentName) {
- const navigate = this.props.navigate
+ const { navigate } = this.props
navigate(componentName, { date: LocalDate.now().toString() })
}
+ toggleShowingMore = () => {
+ this.setState({ isShowingMore: !this.state.isShowingMore })
+ }
+
render() {
- const cycleDayMoreText = this.state.cycleDayNumber ?
- labels.cycleDayKnown(this.state.cycleDayNumber)
- :
+ const { isShowingMore, cycleDayNumber, phase, status } = this.state
+ const { navigate } = this.props
+ const cycleDayMoreText = cycleDayNumber ?
+ labels.cycleDayKnown(cycleDayNumber) :
labels.cycleDayNotEnoughInfo
- const {height, width} = Dimensions.get('window')
return (
-
- this.passTodayTo('CycleDay')}
- style={styles.homeIconElement}
+
+
+ this.passTodayTo('CycleDay') }
+ buttonColor={ cycleDayColor }
+ buttonLabel={ labels.editToday }
>
-
-
- {this.state.cycleDayNumber || labels.unknown}
-
-
+
+ {cycleDayNumber || labels.unknown}
+
- { this.state.showMore &&
+ { isShowingMore &&
{cycleDayMoreText}
}
+
-
-
-
-
- this.passTodayTo('BleedingEditView')}
- style={styles.homeIconElement}
+ this.passTodayTo('BleedingEditView') }
+ buttonColor={ periodColor }
+ buttonLabel={ labels.trackPeriod }
>
-
-
- {this.state.bleedingPredictionRange}
-
-
- {this.state.showMore &&
+
+ {this.state.bleedingPredictionRange}
+
+
+ { isShowingMore &&
{this.state.predictionText}
}
+
-
-
-
-
- this.props.navigate('Chart')}
- style={styles.homeIconElement}
+ navigate('Chart') }
+ buttonColor={ secondaryColor }
+ buttonLabel={ labels.checkFertility }
>
-
-
-
- {this.state.phase ?
- this.state.phase.toString()
- :
- labels.unknown
- }
-
-
- {this.state.phase &&
-
- {`${labels.phase(this.state.phase)} (${this.state.status})`}
-
- }
- {this.state.showMore &&
-
- {this.state.statusText}
-
- }
+
+ { phase ? phase.toString() : labels.unknown }
+
-
-
+ { phase &&
+ {`${labels.phase(phase)} (${status})`}
+ }
+ { isShowingMore &&
+
+
+ {this.state.statusText}
+
+
+ }
+
-
-
- {!this.state.showMore &&
- this.setState({showMore: true})}
- style={[styles.showMore, {
- top: height / 2 - styles.header.height - 30,
- left: width - 40
- }]}
- >
-
- {shared.more}
-
-
-
- }
-
- {this.state.showMore &&
- this.setState({showMore: false})}
- style={[styles.showLess, {
- top: height / 2 - styles.header.height - 30,
- left: 10
- }]}
- >
-
- {shared.less}
-
-
-
- }
+
)
}