UpdateSource "weekScroll" getting fired mysetriously after "dayPress" on TimelineList Component
Description
Changing date after initial load sometimes brings user back to the current date with the "onDateChanged" updateSource "weekScroll".
it first fires updateSource of type "dayPress" (which is correct) and then it fires another event called "weekScroll" and takes the user back to today's date.
Expected Behavior
Only fire the Fire "onDateChanged" once i.e. with "dayPress" when the user presses a date manually.
Observed Behavior
Fires "dayPress" and then fires "weekScroll" (I never scrolled through the week :c) event on user day press in the visible week
No errors, but it fires "onDateChanged" twice on user click.
Here is a video of the issue on the app: https://github.com/wix/react-native-calendars/assets/52943748/5c2dedba-5945-4097-960e-473a28ffc8ce
Here is the video on debugger log (apologies for separate video, just had to make sure that I don't share what I shouldn't) : https://github.com/wix/react-native-calendars/assets/52943748/5e5552ac-0f5c-4cfe-85d8-474c8f5cc39c
Environment
"react-native": "0.72.7","react-native-calendars": "^1.1302.0",
- Replicated on both iOS (both iPad v17.0 and iPhone v17.0) and android devices
Screenshots
Video posted in "Observed Behavior" section should hopefully be helpful to see what the issue is
Sample Code
Kinda same as the example code provided with the repo: https://github.com/wix/react-native-calendars/blob/master/example/src/screens/timelineCalendarScreen.tsx
import {
TimelineEventProps,
TimelineList,
CalendarUtils,
ExpandableCalendar,
CalendarProvider,
CalendarContextProviderProps,
ExpandableCalendarProps,
} from 'react-native-calendars';
...
const selectedDate = .... ---> Date from local state or selected from redux state
const handleChangeDate = (date:string, updateSource: string) => {
console.log("DATE INSIDE handleChangeDate", date);
console.log("updateSource (REASON OF UPDATE)", updateSource);
//UPDATE LOCAL STATE / DISPATCH REDUX ACTION TO UPDATE THE STATE
}
return (
<CalendarProvider
showTodayButton
todayBottomMargin={30}
onDateChanged={handleChangeDate}
date={selectedDate ?? format(new Date(), 'yyyy-MM-dd')}
>
<ExpandableCalendar
theme={{
arrowStyle: { padding: 0, margin: 0 },
textDayFontWeight: '400',
textMonthFontSize: 20,
textMonthFontWeight: '400',
}}
firstDay={0}
minDate={format(subYears(new Date(), 3), 'yyyy-MM-dd')}
maxDate={format(addYears(new Date(), 5), 'yyyy-MM-dd')}
allowSelectionOutOfRange={false}
{...(loading ?
{
displayLoadingIndicator: true,
disabledByDefault: true,
disableWeekScroll: true,
disablePan: true,
disableMonthChange: true,
disableArrowLeft: true,
disableArrowRight: true,
disableAllTouchEventsForInactiveDays: true,
disableAllTouchEventsForDisabledDays: true,
} :
{})
} />
<TimelineList
events={eventsByDate}
scrollToNow
showNowIndicator
timelineProps={{
theme: {
event: {
borderWidth: 0,
borderColor: 'transparent',
borderRadius: 3,
},
timeLabel: {
fontSize: 14 / currentFontScale,
},
},
format24h: true,
onEventPress: handlePressEvent,
overlapEventsSpacing: 5,
rightEdgeSpacing: 10,
}}
initialTime={{ hour: 7, minutes: 0 }}
/>
</CalendarProvider>
)
Only solution to stop the above behavior that I found was to ALWAYS pass
disableWeekScroll={true}
to the ExpandableCalendar component (before I was only passing it when loading as I wanted to stop certain user action when API is loading).
But again, putting this will stop the swipe left and right actions on the small header calendar (when showing week).
This is also an issue for me:
- Lets say today is a Thursday
- I set
dateon<CalendarProvider>to Tuesday of this week - Swipe to next week
- Now Monday is selected (unexpected behavior, as I've specifically set the date)
- Swipe back to this week
- Thursday (today) is selected
I would expect the selected date to always be the one I set in the second step.
@jezzdk did you find any solution to this?