BugiDev / BugiDev/react-native-calendar-strip

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

Open
#333 1 comment 3 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
976
Forks
336
PR merge metrics
No merged PRs in 30d

Description

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);
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.