BugiDev / react-native-calendar-strip

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

Calendar strip scrolls back to selectedDate when component re-renders. #333

Open elvisguillen opened 2 years ago

elvisguillen commented 2 years ago

I'm currently fetching new calendar dates for markedDates when onWeekChanged is triggered. If the component has a selectedDate, it thinks the selectedDate has changed on rerender, even though it has not which triggers it to scroll to selectedDate when markedDates changes.

I found this snippet in Scroller.js line 96 thanks to the latest post on this issue https://github.com/BugiDev/react-native-calendar-strip/issues/321#issuecomment-990067754

if (selectedDate !== prevProps.renderDayParams.selectedDate) {
   this.scrollToDate(selectedDate);
}

Since selectedDate is using moment internally which is a function, this check is always true even if the dates are the same, regardless of being a moment variable or string. I was able to fix it by changing that condition to use moment's built in equal function.

if (!selectedDate.isSame(prevProps.renderDayParams.selectedDate)) {
      this.scrollToDate(selectedDate);
 }
StackTraceYo commented 1 year ago

I am using patch-package to fix this issue - anychance we could get this in? I could do a PR