BugiDev / react-native-calendar-strip

Easy to use and visually stunning calendar component for React Native.
MIT License
939 stars 327 forks source link

Fix initial week. #151

Closed EgorZotov closed 4 years ago

EgorZotov commented 4 years ago

If initial week is not first week, it will show only first week. This fix sets week data based on initial selectedDate.

peacechen commented 4 years ago

Thanks @EgorZotov for finding a solution to the bug.

There may be a problem with the initialization of selectedDate. If it's not provided, moment(undefined) will create today's date. The calendar strip will always set today as selected, even if the caller didn't supply it. Would you verify that?

EgorZotov commented 4 years ago

Sooo, Long time no see :) It is not proper fix in any way. I fixed it with setting initial date based on week adjustments in componentDidMount but it is not a proper way too. I assume that componentDidUpdate is not setting starting week properly in case startingDate arriving after selectedDate. It can cause calendar to set week start on startingDate without adjusting week start properly. https://github.com/BugiDev/react-native-calendar-strip/blob/4e8bf2a47332dd7da2fd564f8f786a0a5b63afca/src/CalendarStrip.js#L179-L190

I think that week start should be adjusted like update based on selectedDate through this.updateWeekStart. https://github.com/BugiDev/react-native-calendar-strip/blob/4e8bf2a47332dd7da2fd564f8f786a0a5b63afca/src/CalendarStrip.js#L164-L177

I am sorry for that premature pull request) I can't test my theory right now but i will do pull request some time later after i have time to test it properly.