Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#283] Invoking handleOnPressDay updates the visible month to the given date #386

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion CalendarPicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,15 @@ export default class CalendarPicker extends Component {
this.setState({
selectedStartDate,
selectedEndDate,
renderMonthParams: this.createMonthProps({ ...this.state, selectedStartDate, selectedEndDate }),
currentMonth: month,
currentYear: year,
renderMonthParams: this.createMonthProps({
...this.state,
currentMonth: month,
currentYear: year,
selectedStartDate,
selectedEndDate
}),
}, () => {
// Sync start date with parent *after* state update.
onDateChange(this.state.selectedStartDate, Utils.START_DATE);
Expand Down
13 changes: 13 additions & 0 deletions example/example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export default class App extends Component {
this.toggleEnableRange = this.toggleEnableRange.bind(this);
this.onMinRangeDuration = this.onMinRangeDuration.bind(this);
this.onMaxRangeDuration = this.onMaxRangeDuration.bind(this);
this.onSelectToday = this.onSelectToday.bind(this);

this.calendarRef = React.createRef(null);
}

onDateChange(date, type) {
Expand Down Expand Up @@ -94,6 +97,11 @@ export default class App extends Component {
});
}

onSelectToday() {
const today = new Date()
this.calendarRef.current.handleOnPressDay({ day: today.getDate(), month: today.getMonth(), year: today.getFullYear() })
}

customDayHeaderStylesCallback({ dayOfWeek, month, year }) {
switch (dayOfWeek) {
case 4: // Thursday
Expand Down Expand Up @@ -127,6 +135,7 @@ export default class App extends Component {
return (
<View style={styles.container}>
<CalendarPicker
ref={this.calendarRef}
scrollable
selectedStartDate={selectedStartDate}
selectedEndDate={selectedEndDate}
Expand Down Expand Up @@ -154,6 +163,10 @@ export default class App extends Component {
<Button onPress={this.clear} title="Clear Selection" />
</View>

<View style={styles.topSpacing}>
<Button onPress={this.onSelectToday} title="Select today" />
</View>

<View style={styles.topSpacing}>
<Text style={styles.text}>Range select:</Text>
</View>
Expand Down