react-native-calendars: Agenda crashes with RN 0.78

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 7
  • Comments: 32 (9 by maintainers)

Most upvoted comments

I was messing around a little bit, and the issue seems to be coming from here in the ReservationList component class.

componentDidUpdate(prevProps) {
  if (this.props.topDay && prevProps.topDay && prevProps !== this.props) {
    if (!sameDate(prevProps.topDay, this.props.topDay)) {
      this.setState({ reservations: [] }, () => this.updateReservations(this.props));
    } else {
      this.updateReservations(this.props);
    }
  }
}

I think the problem is with the prevProps !== this.props check. I modified it slightly to test it out:

componentDidUpdate(prevProps) {
  if (this.props.topDay && prevProps.topDay && 
      (!sameDate(prevProps.topDay, this.props.topDay) || 
       prevProps.items !== this.props.items || 
       prevProps.selectedDay !== this.props.selectedDay)) {
    
    if (!sameDate(prevProps.topDay, this.props.topDay)) {
      this.setState({ reservations: [] }, () => this.updateReservations(this.props));
    } else {
      this.updateReservations(this.props);
    }
  }
}

This initially fixes it when you are looking at the current week at the top, but when you switch to the full month selection that no longer works. So there is more that needs done or updated, or maybe i missed the true issue completely.

I created a PR, with slightly updated coding. It looks the the other error I encountered is only on Android devices, and is there even in the current version on older version or RN as well.

Here is a link to the PR

There are at least 2 PR’s with fixes. Let’s see what WIX team will do about it.

Code example:

import React, {useState} from 'react';
import {StatusBar, View} from 'react-native';
import {Agenda, CalendarProvider} from 'react-native-calendars';

function App(): React.JSX.Element {
  const [currentDate, setCurrentDate] = useState(new Date().toDateString());

  return (
    <View>
      <StatusBar barStyle={'light-content'} />

      <CalendarProvider date={currentDate}>
        <Agenda />
      </CalendarProvider>
    </View>
  );
}

export default App;

Open your project directory.

Navigate to: node_modules/react-native-calendars/src/agenda/reservation-list/index.js Open the File for Editing

Open index.js.

Find the componentDidUpdate Method

Search for componentDidUpdate in the file.

Replace the Method with the Updated One

Replace the existing componentDidUpdate with the following code:

componentDidUpdate(prevProps) { if ( this.props.topDay && prevProps.topDay && ( !sameDate(prevProps.topDay, this.props.topDay) || prevProps.items !== this.props.items || prevProps.selectedDay !== this.props.selectedDay ) ) { if (!sameDate(prevProps.topDay, this.props.topDay)) { this.setState({ reservations: [] }, () => this.updateReservations(this.props)); } else { this.updateReservations(this.props); } } }

#2624 is a possible fix. Let’s see what the team chooses to implement.

The app is crashed on iOS.

react-native:0.78.0 and react-native-calendars:1.1310.0

Image

I got the same error. The issue is related with React 19 which is shipped with RN 0.78. When I downgraded to RN 0.77 with React 18.3.1, the issue is solved.

I’ve encountered various bugs with React 19 when using other packages, so it’s safer to stick with the previous version for now.

#2624 is a possible fix. Let’s see what the team chooses to implement.

@shareef-dweikat - It’s mentioned above

I have the same issue as @gkasireddy202 onDayPress does get called, I can alert a success. I have to click around a-lot before the agenda view opens.

This only happens to me on an older Android version (version 14) and in release mode, doesn’t happen in development. react-native: 0.78.0 react-native-calendars: 1.1312.0

I’ve tried a few other versions of react-native-calendars and get the same issue, also tried the patch.

calendar.mp4

@Lewitje , @gkasireddy202 It looks like this has a different cause. Maybe you fill in another issue.