Search code examples
javascriptreact-nativecalendarexpoexpo-calendar

Expo React Native Calendar - Error: Exception in HostFunction: Malformed calls from JS: field sizes are different


I am trying to add an event from the app to the device calendar using Expo Calendar. This is my render function:

export default class MatchStatsScreen extends Component {
  
  render() {
   return (
      <View style={styles.container}>
        <TouchableOpacity
          style={styles.button}
          onPress={() => {
            addCalEvent()
          }}>
          <Text>Add Event to Calendar</Text>
        </TouchableOpacity>
      </View>
    );
  }
};

and this is the function im trying to use to add the calendar event:

async function addCalEvent(){
if (Calendar.getCalendarPermissionsAsync() != "granted") {
     Calendar.requestCalendarPermissionsAsync();
     if (Platform.OS == "ios") {
        Calendar.requestRemindersPermissionsAsync();
      }

  }
  const calendars = await Calendar.getCalendarsAsync();
  let today = moment(new Date());
  let end = new Date();
  end = moment(end).add(1, 'hour');
  const selectedCalendar = calendars.find((calendar) => calendar.id === "345AE74C-8063-4841-85E8-18790840005B")
  const details = {
          title: "Test Event",
          startDate: today,
          endDate: end,
        };
   try {
            const res = await Calendar.createEventAsync(selectedCalendar.id, details);
            console.log({ res })
        } catch (e) {
            console.log({ e })
        }
}

The error I'm logging in my console is:

Object {
  "e": [Error: Exception in HostFunction: Malformed calls from JS: field sizes are different.

[[11,131],[0,0],[[724,2000,1593975502364,false]],3256]],
}

I've confirmed the calendar id is pointing to a legitimate calendar with the ability to be modified and that the dates are formatted correctly. Additionally, I have already given Expo permission to modify my calendars. I'm not sure what else to try at this point. Any ideas would be helpful. Thank you!


Solution

  • I don't know if you already found the solution to your problem but i just had the same issue and fixed it by creating an instance of Date for startDate & endDate. Look at my example :

    let today = new Date();
    let end = new Date(moment().add(1, 'hour'));
    

    I hope it will help you.