stephy / CalendarPicker

CalendarPicker Component for React Native
803 stars 373 forks source link

Using restrictMonthNavigation prop without maxDate prop? #230

Closed Roka20012 closed 4 years ago

Roka20012 commented 4 years ago

Hey guys 👋

When I trying to select a year without providing maxDate prop I am getting this error. So I need restrictMonthNavigation for past dates but not for future dates

Question ❓

How I can use restrictMonthNavigation for past dates without providing maxDate because without it I also getting this bug month shifting bug

Error 🚨

image

Code 👨‍💻

<CalendarPicker
    onDateChange={onChangeDate}
    restrictMonthNavigation
    weekdays={WEEKDAYS}
    minDate={minDate}
    scrollable
/>

Video 🎬

ezgif com-video-to-gif

peacechen commented 4 years ago

Thanks for reporting this bug. If you have time to debug this, please submit a PR and I'll merge right away.

saaketnarnolia commented 4 years ago

I am facing this error too.

peacechen commented 4 years ago

This may be the problem in YearsHeader.js:

  const disablePrevious = restrictNavigation && (minDate.year() >= year);
  const disableNext = restrictNavigation && (maxDate.year() <= year);

https://github.com/stephy/CalendarPicker/blob/master/CalendarPicker/YearsHeader.js#L31

It should check for valid minDate and maxDate, e.g.

  const disableNext = restrictNavigation && maxDate && (maxDate.year() <= year);

Please test that and submit a PR if it works.