Replace binds with lambdas
This commit is contained in:
+13
-14
@@ -19,8 +19,18 @@ export default class App extends Component {
|
|||||||
this.state = {
|
this.state = {
|
||||||
currentPage: 'Home'
|
currentPage: 'Home'
|
||||||
}
|
}
|
||||||
|
this.backHandler = BackHandler.addEventListener('hardwareBackPress', this.handleBackButtonPress)
|
||||||
|
}
|
||||||
|
|
||||||
const handleBackButtonPress = function() {
|
componentWillUnmount() {
|
||||||
|
this.backHandler.remove()
|
||||||
|
}
|
||||||
|
|
||||||
|
navigate = (pageName, props) => {
|
||||||
|
this.setState({currentPage: pageName, currentProps: props})
|
||||||
|
}
|
||||||
|
|
||||||
|
handleBackButtonPress = () => {
|
||||||
if (this.state.currentPage === 'Home') return false
|
if (this.state.currentPage === 'Home') return false
|
||||||
if (isSymptomView(this.state.currentPage)) {
|
if (isSymptomView(this.state.currentPage)) {
|
||||||
this.navigate('CycleDay', { cycleDay: this.state.currentProps.cycleDay })
|
this.navigate('CycleDay', { cycleDay: this.state.currentProps.cycleDay })
|
||||||
@@ -28,17 +38,6 @@ export default class App extends Component {
|
|||||||
this.navigate('Home')
|
this.navigate('Home')
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}.bind(this)
|
|
||||||
|
|
||||||
this.backHandler = BackHandler.addEventListener('hardwareBackPress', handleBackButtonPress)
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillUnmount() {
|
|
||||||
this.backHandler.remove()
|
|
||||||
}
|
|
||||||
|
|
||||||
navigate(pageName, props) {
|
|
||||||
this.setState({currentPage: pageName, currentProps: props})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -51,12 +50,12 @@ export default class App extends Component {
|
|||||||
{this.state.currentPage != 'CycleDay' && <Header title={titles[this.state.currentPage]} />}
|
{this.state.currentPage != 'CycleDay' && <Header title={titles[this.state.currentPage]} />}
|
||||||
|
|
||||||
{React.createElement(page, {
|
{React.createElement(page, {
|
||||||
navigate: this.navigate.bind(this),
|
navigate: this.navigate,
|
||||||
...this.state.currentProps
|
...this.state.currentProps
|
||||||
})}
|
})}
|
||||||
|
|
||||||
{!isSymptomView(this.state.currentPage) &&
|
{!isSymptomView(this.state.currentPage) &&
|
||||||
<Menu navigate={this.navigate.bind(this)} />
|
<Menu navigate={this.navigate} />
|
||||||
}
|
}
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export default class CalendarView extends Component {
|
|||||||
bleedingDaysSortedByDate.removeListener(this.setStateWithCalFormattedDays)
|
bleedingDaysSortedByDate.removeListener(this.setStateWithCalFormattedDays)
|
||||||
}
|
}
|
||||||
|
|
||||||
passDateToDayView(result) {
|
passDateToDayView = (result) => {
|
||||||
const cycleDay = getOrCreateCycleDay(result.dateString)
|
const cycleDay = getOrCreateCycleDay(result.dateString)
|
||||||
const navigate = this.props.navigate
|
const navigate = this.props.navigate
|
||||||
navigate('CycleDay', { cycleDay })
|
navigate('CycleDay', { cycleDay })
|
||||||
@@ -34,7 +34,7 @@ export default class CalendarView extends Component {
|
|||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<CalendarList
|
<CalendarList
|
||||||
onDayPress={this.passDateToDayView.bind(this)}
|
onDayPress={this.passDateToDayView}
|
||||||
markedDates={this.state.bleedingDaysInCalFormat}
|
markedDates={this.state.bleedingDaysInCalFormat}
|
||||||
markingType={'period'}
|
markingType={'period'}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export default class CycleDayOverView extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
goToCycleDay(target) {
|
goToCycleDay = (target) => {
|
||||||
const localDate = LocalDate.parse(this.state.cycleDay.date)
|
const localDate = LocalDate.parse(this.state.cycleDay.date)
|
||||||
const targetDate = target === 'before' ?
|
const targetDate = target === 'before' ?
|
||||||
localDate.minusDays(1).toString() :
|
localDate.minusDays(1).toString() :
|
||||||
@@ -55,7 +55,7 @@ export default class CycleDayOverView extends Component {
|
|||||||
isCycleDayOverView={true}
|
isCycleDayOverView={true}
|
||||||
cycleDayNumber={cycleDayNumber}
|
cycleDayNumber={cycleDayNumber}
|
||||||
date={cycleDay.date}
|
date={cycleDay.date}
|
||||||
goToCycleDay={this.goToCycleDay.bind(this)}
|
goToCycleDay={this.goToCycleDay}
|
||||||
/>
|
/>
|
||||||
<ScrollView>
|
<ScrollView>
|
||||||
<View style={styles.symptomBoxesView}>
|
<View style={styles.symptomBoxesView}>
|
||||||
@@ -134,7 +134,10 @@ function getLabel(symptomName, symptom) {
|
|||||||
cervix: cervix => {
|
cervix: cervix => {
|
||||||
let cervixLabel = []
|
let cervixLabel = []
|
||||||
if (cervix.opening > -1 && cervix.firmness > -1) {
|
if (cervix.opening > -1 && cervix.firmness > -1) {
|
||||||
cervixLabel.push(openingLabels[cervix.opening], firmnessLabels[cervix.firmness])
|
cervixLabel.push(
|
||||||
|
openingLabels[cervix.opening],
|
||||||
|
firmnessLabels[cervix.firmness]
|
||||||
|
)
|
||||||
if (cervix.position > -1) {
|
if (cervix.position > -1) {
|
||||||
cervixLabel.push(positionLabels[cervix.position])
|
cervixLabel.push(positionLabels[cervix.position])
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -8,7 +8,7 @@ import styles, { iconStyles } from '../styles'
|
|||||||
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'
|
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'
|
||||||
|
|
||||||
export default class Menu extends Component {
|
export default class Menu extends Component {
|
||||||
makeMenuItem({ title, icon, onPress}, i) {
|
makeMenuItem = ({ title, icon, onPress}, i) => {
|
||||||
return (
|
return (
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
onPress={onPress}
|
onPress={onPress}
|
||||||
@@ -36,7 +36,7 @@ export default class Menu extends Component {
|
|||||||
{ title: 'Chart', icon: 'chart-line', onPress: () => this.goTo('Chart') },
|
{ title: 'Chart', icon: 'chart-line', onPress: () => this.goTo('Chart') },
|
||||||
{ title: 'Stats', icon: 'chart-pie', onPress: () => this.goTo('Stats') },
|
{ title: 'Stats', icon: 'chart-pie', onPress: () => this.goTo('Stats') },
|
||||||
{ title: 'Settings', icon: 'settings', onPress: () => this.goTo('Settings') },
|
{ title: 'Settings', icon: 'settings', onPress: () => this.goTo('Settings') },
|
||||||
].map(this.makeMenuItem.bind(this))}
|
].map(this.makeMenuItem)}
|
||||||
</View >
|
</View >
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user