wix / react-native-calendars

React Native Calendar Components 🗓️ 📆
MIT License
9.6k stars 2.96k forks source link

WeekCalendar - on scroll ended? Trying to do something after the WeekCalendar has been scrolled... #2498

Closed workbyken closed 4 months ago

workbyken commented 4 months ago

I'm trying to do something after the WeekCalendar has been scrolled, eg. set the current Month title of the visible week.

I've tried:

onScroll, onScrollBeginDrag, onScrollEndDrag, onMomentumScrollBegin, onMomentumScrollEnd,

is it possible to do this at all?

Expected Behavior

Nothing

Observed Behavior

Nothing

Environment

Reproducible Demo

Screenshots

jacob30 commented 4 months ago

onDateChanged from the CalendarProvider fires after WeekCalendar has been scrolled

workbyken commented 4 months ago

It is not behaving as you have mentioned. It only fires when you press a day, not when you are just scrolling through the weeks, or im doing something wrong?

const handleChangeDate = (date:string, updateSource: string) => {
    console.log("DATE INSIDE handleChangeDate", date);
    console.log("updateSource (REASON OF UPDATE)", updateSource);
  }

<CalendarProvider onDateChanged={handleChangeDate} date={selectedDate}>
            <WeekCalendar
              firstDay={1}
              current={selectedDate}
              onDayPress={onDayPress}
              monthFormat={'yyyy MM'}
              markingType={'multi-dot'}
              markedDates={markedDates}
            />
</CalendarProvider>
jacob30 commented 4 months ago

Using the code in example/src/screens/expandableCalendarScreen.tsx with your handleChangeDate fn:

DATE INSIDE handleChangeDate 2024-08-19
LOG  updateSource (REASON OF UPDATE) pageScroll

When you scroll the weeks does the date change?

workbyken commented 4 months ago

Got it, thanks - I had to import useRef! import React, { useRef, useEffect, useState, useCallback, useLayoutEffect } from 'react';