Skip to content

Commit

Permalink
Fix corner case bug with month header using scrollable (#203).
Browse files Browse the repository at this point in the history
On some projects created with `react-native init`, onLayout fires later and resets weekStartDate & weekEndDate.
  • Loading branch information
peacechen committed Jun 22, 2020
1 parent 7a1bee1 commit ff6a7d9
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/CalendarStrip.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,19 +465,25 @@ class CalendarStrip extends Component {
}
}

const weekStartDate = datesList[0].date;
const weekEndDate = datesList[this.state.numVisibleDays - 1].date;
const _weekStartDate = weekStartDate && weekStartDate.clone();
const _weekEndDate = weekEndDate && weekEndDate.clone();
onWeekChanged && onWeekChanged(_weekStartDate, _weekEndDate);

return {
const newState = {
days,
datesList,
initialScrollerIndex,
weekStartDate,
weekEndDate,
};

if (!scrollable) {
const weekStartDate = datesList[0].date;
const weekEndDate = datesList[this.state.numVisibleDays - 1].date;
newState.weekStartDate = weekStartDate;
newState.weekEndDate = weekEndDate;

const _weekStartDate = weekStartDate && weekStartDate.clone();
const _weekEndDate = weekEndDate && weekEndDate.clone();
onWeekChanged && onWeekChanged(_weekStartDate, _weekEndDate);
}
// else Scroller sets weekStart/EndDate and fires onWeekChanged.

return newState;
}

renderDay(props) {
Expand Down

0 comments on commit ff6a7d9

Please sign in to comment.