vonovak / react-native-add-calendar-event

Create, view or edit events in react native using the standard iOS / Android dialogs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

presentEventCreatingDialog did not return eventId and calenderItemIdentifier

mabudiman opened this issue · comments

eventInfo from promise presentEventCreatingDialog return { action: 'CANCELED' } instead { action: 'SAVED', eventIdentifier: string, calendarItemIdentifier: string } when event saved by user.

import React from 'react';
import {
  StyleSheet,
  Button,
  View,
} from 'react-native';

import * as AddCalendarEvent from 'react-native-add-calendar-event'

class App extends React.Component<any,any> {

  onClickAddEvent = () => {
    const eventConfig = {
      title : 'Title',	
      startDate	: '2020-01-31T10:10:10.111Z',
      endDate	: '2020-01-31T11:10:10.111Z',
      location : 'Work Place',
      allDay : false
    };
    
    AddCalendarEvent.presentEventCreatingDialog(eventConfig)
      .then((eventInfo) => {
      // .then((eventInfo: { calendarItemIdentifier: string, eventIdentifier: string }) => {
        // handle success - receives an object with `calendarItemIdentifier` and `eventIdentifier` keys, both of type string.
        // These are two different identifiers on iOS.
        // On Android, where they are both equal and represent the event id, also strings.
        // when { action: 'CANCELED' } is returned, the dialog was dismissed
        console.warn(JSON.stringify(eventInfo));
      })
      .catch((error: string) => {
        // handle error such as when user rejected permissions
        console.warn(error);
      });
  }

  render() {
    return (
      <View>
        <View style={styles.button}>
          <Button title='add event' onPress={() => this.onClickAddEvent()}/>
        </View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  button: {
    paddingHorizontal: 15,
    paddingTop: 20,
  }
});

export default App;

I'm using android 9 pie. am i missing something?

It's mentioned here too #89

yes, it's currently possible that the result is wrong, because the native apis on android are pretty horrible. This can be improved if you dig into it, but I'm not currently using this module so I don't have plans to do so. Help is appreciated.

Please could you put a warning on this package and state clearly that "this module is not reliable with android and lead to unpredictable results ?". I have "wasted" a fair amount of time configuring and installing it to get at the end a false positive CANCELED EVENT raised to the user. The event is saved and my application display "the event has been cancelled"....

Same application same version deployed on stores : Samsung Galaxy S7 => SAVED event returned in the promise, Samsung Galaxy S10 => CANCELED.
Clearly it is not reliable.

@dngconsulting I wanted to share my knowledge on this. Google's native calendar app takes over the "Activity" and RN app goes into background, once resumed the callbacks are replayed however "canceled"
For "skinned" android systems like Samsung and Samsung One UI, Huawei, etc , the calendar is a separate app and successfully returns and replays state with a full object.

Hope its helpful to others

@jeveloper
I am used that react-native-add-calendar-event package.
click addToCalendar function ,
export const addToCalendar = () => {
const eventConfig = {
title: "eventTitle",
startDate: utcDateToString(moment.utc()),
endDate: utcDateToString(moment.utc().add(1, "hours")),
notes: "tasty!",
navigationBarIOS: {
translucent: false,
tintColor: "orange",
barTintColor: "orange",
backgroundColor: "green",
titleColor: "blue",
},
};
request(
Platform.select({
ios: PERMISSIONS.IOS.CALENDARS,
default: PERMISSIONS.ANDROID.WRITE_CALENDAR,
})
)
.then((result) => {
if (result !== RESULTS.GRANTED) {
throw new Error(No permission: ${result});
}
return AddCalendarEvent.presentEventCreatingDialog(eventConfig);
})
.then((eventInfo) => {
console.warn(JSON.stringify(eventInfo));
})
.catch((error) => {
console.warn(error);
});
}

The app is crash like goes to the background
I couldn't find solution what is the cause of the problem

@kannan-rjp Hi, Just following up, much later than I would've. Can you paste your piece of code in something more readable for me and others please. Also, I would recommend looking at expo libraries or others that are maintained. Crashing information should be logged