Skip to content

Add status property for iOS #423 #424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ npm-debug.log
.DS_Store
android/build/*
xcuserdata
.yarn
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
80 changes: 41 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,39 +276,40 @@ RNCalendarEvents.saveEvent(title, {
Creating events is fairly straightforward. Hopefully the following explanation can help.

##### Basic `saveEvent`

For both iOS and Android the pattern is simple; the event needs a `title` as well as a `startDate` and `endDate`. The `endDate` should also be a date later than the `startDate`.

```javascript
RNCalendarEvents.saveEvent('Title of event', {
startDate: '2016-08-19T19:26:00.000Z',
endDate: '2017-08-19T19:26:00.000Z'
})
RNCalendarEvents.saveEvent("Title of event", {
startDate: "2016-08-19T19:26:00.000Z",
endDate: "2017-08-19T19:26:00.000Z",
});
```

##### Specify a calendar `saveEvent`

The example above will simply save the event to your devices default calendar. If you wish to control which calendar the event is saved to, you must provide the `calendarId`. This will ensure your event is saved to an expected calendar.

```javascript
RNCalendarEvents.saveEvent('Title of event', {
calendarId: '141',
startDate: '2016-08-19T19:26:00.000Z',
endDate: '2017-08-19T19:26:00.000Z'
})
RNCalendarEvents.saveEvent("Title of event", {
calendarId: "141",
startDate: "2016-08-19T19:26:00.000Z",
endDate: "2017-08-19T19:26:00.000Z",
});
```

##### Additional fields with `saveEvent`

There are also other writable fields available. For example, you may wish to specify the location of the event or add additional notes for the event. Complete list of fields can be found [in the wiki](https://github.com/wmcmahan/react-native-calendar-events/wiki/Event-Fields#event-details).

```javascript
RNCalendarEvents.saveEvent('Title of event', {
calendarId: '141',
startDate: '2016-08-19T19:26:00.000Z',
endDate: '2017-08-19T19:26:00.000Z',
location: 'Los Angeles, CA',
notes: 'Bring sunglasses'
})
RNCalendarEvents.saveEvent("Title of event", {
calendarId: "141",
startDate: "2016-08-19T19:26:00.000Z",
endDate: "2017-08-19T19:26:00.000Z",
location: "Los Angeles, CA",
notes: "Bring sunglasses",
});
```

### `removeEvent`
Expand All @@ -331,29 +332,30 @@ Returns: **Promise**

## Event fields

| Property | Type | Description | iOS | Android |
| :--------------------------------------------------- | :----- | :---------------------------------------------------------------------------------------------------- | :-: | :-----: |
| **id\*** | String | Unique id for the calendar event. | ✓ | ✓ |
| **calendarId\*\*** | String | Unique id for the calendar where the event will be saved. Defaults to the device's default calendar. | ✓ | ✓ |
| **title** | String | The title for the calendar event. | ✓ | ✓ |
| **startDate** | String | The start date of the calendar event in ISO format. | ✓ | ✓ |
| **endDate** | String | The end date of the calendar event in ISO format. | ✓ | ✓ |
| **allDay** | Bool | Indicates whether the event is an all-day |
| event. | ✓ | ✓ |
| **recurrence** | String | The simple recurrence frequency of the calendar event `daily`, `weekly`, `monthly`, `yearly` or none. | ✓ | ✓ |
| [**recurrenceRule**](#recurrence-rule) \*\* | Object | The events recurrence settings. | ✓ | ✓ |
| **occurrenceDate\*** | String | The original occurrence date of an event if it is part of a recurring series. | ✓ | |
| **isDetached** | Bool | Indicates whether an event is a detached instance of a repeating event. | ✓ | |
| **url** | String | The url associated with the calendar event. | ✓ | |
| **location** | String | The location associated with the calendar event. | ✓ | ✓ |
| [**structuredLocation**](#alarm-structuredlocation) | String | The structuredLocation associated with the calendar event. | ✓ | |
| **notes** | String | The notes associated with the calendar event. | ✓ | |
| **description** | String | The description associated with the calendar event. | | ✓ |
| [**alarms**](#alarms) | Array | The alarms associated with the calendar event, as an array of alarm objects. | ✓ | ✓ |
| [**attendees**](#attendees)\* | Array | The attendees of the event, including the organizer. | ✓ | ✓ |
| [**calendar**](#calendar)\* | Object | The calendar containing the event. | ✓ | ✓ |
| **skipAndroidTimezone** | Bool | Skip the process of setting automatic timezone on android | | ✓ |
| **timeZone** | String | The time zone associated with the event | ✓ | |
| Property | Type | Description | iOS | Android |
| :-------------------------------------------------- | :----- | :---------------------------------------------------------------------------------------------------- | :-: | :-----: |
| **id\*** | String | Unique id for the calendar item. | ✓ | ✓ |
| **eventId\*** | String | Unique id for the calendar event. | ✓ | |
| **calendarId\*\*** | String | Unique id for the calendar where the event will be saved. Defaults to the device's default calendar. | ✓ | ✓ |
| **title** | String | The title for the calendar event. | ✓ | ✓ |
| **startDate** | String | The start date of the calendar event in ISO format. | ✓ | ✓ |
| **endDate** | String | The end date of the calendar event in ISO format. | ✓ | ✓ |
| **allDay** | Bool | Indicates whether the event is an all-day | ✓ | ✓ |
| **recurrence** | String | The simple recurrence frequency of the calendar event `daily`, `weekly`, `monthly`, `yearly` or none. | ✓ | ✓ |
| [**recurrenceRule**](#recurrence-rule) \*\* | Object | The events recurrence settings. | ✓ | ✓ |
| **occurrenceDate\*** | String | The original occurrence date of an event if it is part of a recurring series. | ✓ | |
| **isDetached** | Bool | Indicates whether an event is a detached instance of a repeating event. | ✓ | |
| **status** | String | The status of the calendar event `confirmed`, `tentative`, `cancelled`, `none` or `notSupported`. | ✓ | |
| **url** | String | The url associated with the calendar event. | ✓ | |
| **location** | String | The location associated with the calendar event. | ✓ | ✓ |
| [**structuredLocation**](#alarm-structuredlocation) | String | The structuredLocation associated with the calendar event. | ✓ | |
| **notes** | String | The notes associated with the calendar event. | ✓ | |
| **description** | String | The description associated with the calendar event. | | ✓ |
| [**alarms**](#alarms) | Array | The alarms associated with the calendar event, as an array of alarm objects. | ✓ | ✓ |
| [**attendees**](#attendees)\* | Array | The attendees of the event, including the organizer. | ✓ | ✓ |
| [**calendar**](#calendar)\* | Object | The calendar containing the event. | ✓ | ✓ |
| **skipAndroidTimezone** | Bool | Skip the process of setting automatic timezone on android | | ✓ |
| **timeZone** | String | The time zone associated with the event | ✓ | |

### Calendar

Expand Down
30 changes: 29 additions & 1 deletion ios/RNCalendarEvents.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ @interface RNCalendarEvents ()
@end

static NSString *const _id = @"id";
static NSString *const _eventId = @"eventId";
static NSString *const _calendarId = @"calendarId";
static NSString *const _title = @"title";
static NSString *const _location = @"location";
Expand All @@ -24,6 +25,7 @@ @interface RNCalendarEvents ()
static NSString *const _availability = @"availability";
static NSString *const _attendees = @"attendees";
static NSString *const _timeZone = @"timeZone";
static NSString *const _status = @"status";

dispatch_queue_t serialQueue;

Expand Down Expand Up @@ -453,6 +455,25 @@ - (NSMutableArray *)calendarSupportedAvailabilitiesFromMask:(EKCalendarEventAvai
return availabilitiesStrings;
}

- (NSString *)statusStringMatchingConstant:(EKEventStatus)constant
{
switch(constant) {
case EKEventStatusNone:
// The event has no status.
return @"none";
case EKEventStatusConfirmed:
// The event is confirmed.
return @"confirmed";
case EKEventStatusTentative:
//The event is tentative.
return @"tentative";
case EKEventStatusCanceled:
return @"canceled";
default:
return @"notSupported";
}
}

- (NSString *)availabilityStringMatchingConstant:(EKEventAvailability)constant
{
switch(constant) {
Expand Down Expand Up @@ -527,7 +548,8 @@ - (NSDictionary *)serializeCalendarEvent:(EKEvent *)event
@"endDate": @""
},
_availability: @"",
_timeZone: @""
_timeZone: @"",
_status: @""
};

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
Expand All @@ -543,6 +565,10 @@ - (NSDictionary *)serializeCalendarEvent:(EKEvent *)event
[formedCalendarEvent setValue:event.calendarItemIdentifier forKey:_id];
}

if (event.eventIdentifier) {
[formedCalendarEvent setValue:event.eventIdentifier forKey:_eventId];
}

if (event.calendar) {
[formedCalendarEvent setValue:@{
@"id": event.calendar.calendarIdentifier?event.calendar.calendarIdentifier: @"tempCalendar",
Expand Down Expand Up @@ -727,6 +753,8 @@ - (NSDictionary *)serializeCalendarEvent:(EKEvent *)event

[formedCalendarEvent setValue:[self availabilityStringMatchingConstant:event.availability] forKey:_availability];

[formedCalendarEvent setValue:[self statusStringMatchingConstant:event.status] forKey:_status];

@try {
if (event.structuredLocation && event.structuredLocation.radius) {
NSMutableDictionary *structuredLocation = [[NSMutableDictionary alloc] initWithCapacity:3];
Expand Down
8 changes: 7 additions & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,17 @@ interface CalendarEventBase {
description?: string;
/** iOS ONLY - The time zone associated with the event */
timeZone?: string;
/** iOS ONLY – The availability setting for the event. */
availability: "busy" | "free" | "tentative" | "unavailable" | "notSupported";
/** iOS ONLY – The status of the event. */
status: "none" | "tentative" | "confirmed" | "canceled";
}

export interface CalendarEventReadable extends CalendarEventBase {
/** Unique id for the calendar event */
/** Unique id for the calendar item */
id: string;
/** Unique id for the calendar event */
eventId: string;
/** The title for the calendar event. */
title: string;
/** The attendees of the event, including the organizer. */
Expand Down
Loading