react-native-calendars icon indicating copy to clipboard operation
react-native-calendars copied to clipboard

`CalendarProvider` date prop not changing `AgendaList` date

Open KrisLau opened this issue 2 years ago • 6 comments

Please make our job easier by filling this template out to completion. If you're requesting a feature instead of reporting a bug, please feel free to skip the Environment and Reproducible Demo sections.

Description

I'm trying to get the date prop to work for my react-native-calendar and the date didn't change for the initial render and even when I call the setState in the onDayPress. Also pressing the today button doesn't seem to work either? in the picture I hardcode the date prop but i usually have the selectedDay state there. Just did that to test

Expected Behavior

Clicking on a date in the ExpandableCalendar should scroll to selected date in AgendaList

Observed Behavior

it only changes the date in the ExpandableCalendar but not in the AgendaList.

Environment

Please run these commands in the project folder and fill in their results:

├─┬ @notifee/[email protected]
│ └── [email protected] deduped
├─┬ @react-native-async-storage/[email protected]
│ └── [email protected] deduped
├─┬ @react-native-clipboard/[email protected]
│ └── [email protected] deduped
├─┬ @react-native-community/[email protected]
│ └── [email protected] deduped
├─┬ @react-native-community/[email protected]
│ └── [email protected] deduped
├─┬ @react-native-community/[email protected]
│ └── [email protected] deduped
├─┬ @react-native-firebase/[email protected]
│ └── [email protected] deduped
├─┬ @react-native-google-signin/[email protected]
│ └── [email protected] deduped
├─┬ @react-native-masked-view/[email protected]
│ └── [email protected] deduped
├─┬ @react-navigation/[email protected]
│ ├─┬ @react-navigation/[email protected]
│ │ └── [email protected] deduped
│ └── [email protected] deduped
├─┬ @react-navigation/[email protected]
│ └── [email protected] deduped
├─┬ @react-navigation/[email protected]
│ └── [email protected] deduped
├─┬ @rneui/[email protected]
│ ├─┬ [email protected]
│ │ └── [email protected] deduped
│ └─┬ [email protected]
│   └── [email protected] deduped
├─┬ @sentry/[email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └─┬ [email protected]
│   └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected] deduped
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected] invalid: "^3.1.9" from node_modules/@rneui/base
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
└─┬ [email protected]
  └─┬ @react-native-community/[email protected]
    └── [email protected] deduped

Also specify:

  1. Device/emulator/simulator & OS version: iPhone 11 (13.6)

Reproducible Demo

function ExpandableCalendarAgenda(props) {
  ...
  return (
    <CalendarProvider
      date={selectedDay}
      showTodayButton={true}
      disabledOpacity={0.6}
      todayBottomMargin={16}
      onDateChanged={date => setSelectedDay(date)}
      theme={{
        todayButtonTextColor: Colors.WHITE,
      }}
      todayButtonStyle={styles.todayButton}>
      {props.currentScreen === 'UserSchedule' && (
        <ExpandableCalendar
          theme={getTheme()}
          pastScrollRange={60}
          futureScrollRange={60}
          displayLoadingIndicator={true}
          disableAllTouchEventsForDisabledDays
          markedDates={getMarkedDates(eventOccurrencesFormatted)}
          minDate={format(sub(new Date(), {years: 4}), 'yyyy-MM-dd')}
          maxDate={format(add(new Date(), {years: 4}), 'yyyy-MM-dd')}
          onDayPress={({dateString}) => {
            setSelectedDay(dateString);
          }}
          calendarStyle={styles.calendar}
          style={{paddingTop: insets.top - 10}}
        />
      )}
      <AgendaList
        markToday={false}
        windowSize={5}
        scrollToNextEvent
        initialNumToRender={7}
        maxToRenderPerBatch={5}
        onEndReachedThreshold={0.1}
        removeClippedSubviews={false}
        updateCellsBatchingPeriod={30}
        sections={eventOccurrencesFormatted}
        renderItem={({item}) => (
          <EventListItem
            currentScreen={props.currentScreen}
            roles={props?.roles ?? []}
            item={item}
          />
        )}
        contentContainerStyle={{paddingBottom: 80}}
        sectionStyle={styles.section}
      />
    </CalendarProvider>
  );
}

Screenshots

image

KrisLau avatar Aug 03 '22 18:08 KrisLau

@Inbal-Tish Related to #1862. I also tried logging stuff in the agendaList.js and it looks like the problem is in the scrollToSection where the sectionIndex is for some reason resolving to undefined.

EDIT: So I think part of the problem is that the agendaList is not re-rendering/updating the scroll index when the sections are updated. It also seems to be very inconsistent as I've tried closing, re-opening, and navigating to the calendar dozens of times and half the time it scrolls to the current day while the other half of the time, it does not.

Also the today button seems to be disabled all the time now?

KrisLau avatar Aug 04 '22 21:08 KrisLau

@KrisLau Hi. Please remove all selectedDay logic from CalendarProvider props (date and onDateChanged) and from ExpandableCalendar's onDayPress prop. The ExpandableCalendar and its context provider are managing the selection of the date internaly. You should only provide the INITIAL date to the provider's date prop.

Inbal-Tish avatar Aug 23 '22 11:08 Inbal-Tish

@Inbal-Tish I just tried that and it still seems to stay on the same date. I feel like the selectedDay logic was working for me until I updated the package a while back but the problem is I have no idea when it stopped working since I only noticed the error recently

EDIT: Weird, I just put my selectedDay logic back in and it seems to work now. I'm so confused

KrisLau avatar Aug 23 '22 15:08 KrisLau

@KrisLau Did you try running our demo app to see if your bug reproduces there? I can't seem to do that or I'm not sure what the bug is - can you add a video maybe?

Inbal-Tish avatar Aug 24 '22 05:08 Inbal-Tish

@Inbal-Tish Sorry for the super late reply! here's a video of my problem:

https://user-images.githubusercontent.com/46275463/191371294-a94b0ff8-edf6-40a7-bdfe-493a893635ef.mp4

In the video you can see the problem in this issue (clicking on a date not changing the date), calendar not defaulting to current date, as well as the performance issue I've been having from the beginning (VirtualizedList: You have a large list that is slow to update)

KrisLau avatar Sep 20 '22 21:09 KrisLau

@Inbal-Tish Link to a comment I made awhile back with more info about the performance issue:

  • https://github.com/wix/react-native-calendars/issues/1088#issuecomment-1068202765

KrisLau avatar Sep 21 '22 15:09 KrisLau

I believe I am having the same issue. Selecting a date on the expanded calendar has no effect on the AgendaList. Seems to be an issue if the date is farther than the rendered window.

jslok avatar Sep 30 '22 00:09 jslok

@Inbal-Tish Also getting Excessive pending callbacks (not every time but sometimes) and I noticed the expandableCalendar has an issue where if you expand it all the way, wait for a second, and try swipe it close, it refuses to move. The only way to close it is by pulling it down a little and then back up without lifting my finger.

KrisLau avatar Oct 07 '22 21:10 KrisLau

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jan 07 '23 13:01 stale[bot]