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

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

我正在尝试使用 Expo 日历将应用程序中的事件添加到设备日历。这是我的渲染函数:

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>
    );
  }
};

这是我试图用来添加日历事件的函数:

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 })
        }
}

我在控制台中登录的错误是:

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

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

我已确认日历 ID 指向合法的日历,可以修改并且日期格式正确。此外,我已经授予 Expo 修改我的日历的权限。我不确定此时还可以尝试什么。任何想法都会有所帮助。谢谢!

我不知道您是否已经找到问题的解决方案,但我遇到了同样的问题并通过为 startDate 和 endDate 创建一个 Date 实例来修复它。看看我的例子:

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

希望对你有所帮助