vonovak / react-native-add-calendar-event

Create, view or edit events in react native using the standard iOS / Android dialogs
MIT License
351 stars 102 forks source link

presentEventCreatingDialog did not return eventId and calenderItemIdentifier #94

Open mabudiman opened 4 years ago

mabudiman commented 4 years ago

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?

mabudiman commented 4 years ago

It's mentioned here too https://github.com/vonovak/react-native-add-calendar-event/issues/89

vonovak commented 4 years ago

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.

dngconsulting commented 4 years ago

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"....

dngconsulting commented 4 years ago

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.

jeveloper commented 4 years ago

@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

kannan-rjp commented 6 months ago

@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

jeveloper commented 5 months ago

@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

kannan-rjp commented 5 months ago

Ok i will post.

On Tue, 4 Jun 2024 at 22:33, Serge Bornow @.***> wrote:

@kannan-rjp https://github.com/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

— Reply to this email directly, view it on GitHub https://github.com/vonovak/react-native-add-calendar-event/issues/94#issuecomment-2148009835, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOZWTK33SV42MOQBJO4CLP3ZFXXPPAVCNFSM4KKCIKHKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMJUHAYDAOJYGM2Q . You are receiving this because you were mentioned.Message ID: @.***>