Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ import {

export default class Calendar extends PureComponent {

isSelected = true

static get defaultProps() {
return {
date: new Date(),
todayDayInnerStyle: styles.todayDayInner,
dayWeekendTextStyle: styles.dayWeekendText,
onDateSelect: null,
onPrevButtonPress: null,
onNextButtonPress: null,
Expand All @@ -31,6 +35,8 @@ export default class Calendar extends PureComponent {
static get propTypes() {
return {
date: React.PropTypes.object,
todayDayInnerStyle: React.PropTypes.object,
dayWeekendTextStyle: React.PropTypes.object,
onDateSelect: React.PropTypes.func,
onPrevButtonPress: React.PropTypes.func,
onNextButtonPress: React.PropTypes.func,
Expand All @@ -42,12 +48,14 @@ export default class Calendar extends PureComponent {

handleNextButtonPress() {
if (this.props.onNextButtonPress !== null) {
this.isSelected = false
this.props.onNextButtonPress();
}
}

handlePrevButtonPress() {
if (this.props.onPrevButtonPress !== null) {
this.isSelected = false
this.props.onPrevButtonPress();
}
}
Expand All @@ -57,7 +65,7 @@ export default class Calendar extends PureComponent {
const month = this.props.date.getMonth();
const year = this.props.date.getFullYear();
const selectedDate = new Date(year, month, dateNumber);

this.isSelected = true
this.props.onDateSelect(selectedDate);
}
}
Expand Down Expand Up @@ -126,16 +134,15 @@ export default class Calendar extends PureComponent {
const isWeekend = weekDay === 0 || weekDay === 6;

const today = new Date();
const isToday = this.props.date.getDate() === dateNumber &&
this.props.date.getMonth() === today.getMonth() &&
this.props.date.getFullYear() === today.getFullYear();

const isToday = this.props.date.getDate() === dateNumber

return (
<View key={dateNumber} style={styles.dayOuter}>
<TouchableOpacity onPress={() => this.handleDayPress(dateNumber)}>
<View style={[styles.dayInner, isToday ? styles.todayDayInner : {}]}>
<Text style={[styles.dayText, isWeekend ? styles.dayWeekendText : {}]}>
{dateNumber}
<View style={[styles.dayInner, (isToday && this.isSelected) ? this.props.todayDayInnerStyle : {}]}>
<Text style={[styles.dayText, isWeekend ? this.props.dayWeekendTextStyle : {}]}>
{`${dateNumber}`}
</Text>
</View>
</TouchableOpacity>
Expand Down Expand Up @@ -269,4 +276,4 @@ const styles = StyleSheet.create({
schadedText: {
color: "#AAAAAA",
}
});
});