这是indexloc提供的服务,不要输入任何密码
Skip to content

generhim/react-native-calendar-events

 
 

Repository files navigation

React Native Calendar Events

React Native Module for accessing and saving events to iOS and Android calendars.

Install

npm install --save react-native-calendar-events

Link

Check with React Native documention on linking libraries for more details.

react-native link

OS instructions

Usage

import RNCalendarEvents from 'react-native-calendar-events';

Event Properties

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 Date The start date of the calendar event in ISO format.
endDate Date 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 ** Object The events recurrence settings.
occurrenceDate* Date 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.
notes String The notes associated with the calendar event.
description String The description associated with the calendar event.
alarms Array The alarms associated with the calendar event, as an array of alarm objects.
calendar* Object The calendar containing the event.

* Read only, ** Write only

Recurrence Rule properties:

Property Type Description iOS Android
frequency String Event recurring frequency daily, weekly, monthly, yearly
endDate Date Event recurring end date. This overrides occurrence
occurrence Number Number of event occurrences.
interval Number The interval between events of this recurrence.

* Read only, ** Write only

Options:

Property Type Description iOS Android
exceptionDate Date The start date of a recurring event's exception instance. Used for updating single event in a recurring series
futureEvents Bool If true the update will span all future events. If false it only update the single instance.

authorizationStatus

Get calendar authorization status.

RNCalendarEvents.authorizationStatus()

Returns: Promise

  • fulfilled: String - denied, restricted, authorized or undetermined
  • rejected: Error

authorizeEventStore

Request calendar authorization. Authorization must be granted before accessing calendar events.

Android note: This is only necessary for targeted SDK of 23 and higher.

RNCalendarEvents.authorizeEventStore()

Returns: Promise

  • fulfilled: String - denied, restricted, authorized or undetermined
  • rejected: Error

findEventById

Find calendar event by id. Returns a promise with fulfilled found events.

RNCalendarEvents.findEventById(id)

Arguments:

  • id: String - The events unique id.

Returns: Promise

  • fulfilled: Object | null - Found event with unique id.
  • rejected: Error

fetchAllEvents

Fetch all calendar events. Returns a promise with fulfilled found events.

RNCalendarEvents.fetchAllEvents(startDate, endDate, calendars)

Arguments:

  • startDate: Date - The start date of the range of events fetched.
  • endDate: Date - The end date of the range of events fetched.
  • calendars: Array - List of calendar id strings to specify calendar events. Defaults to all calendars if empty.

Returns: Promise

  • fulfilled: Array - Matched events within the specified date range.
  • rejected: Error

saveEvent

Creates calendar event.

RNCalendarEvents.saveEvent(title, details, options);

Arguments:

  • title: String - The title of the event.
  • details: Object - The event's details.
  • options: Object - Options specific to the saved event.

Returns: Promise

  • fulfilled: String - Created event's ID.
  • rejected: Error

Update Event

Give the unique calendar event id to update an existing calendar event.

RNCalendarEvents.saveEvent(title, {id: 'FE6B128F-C0D8-4FB8-8FC6-D1D6BA015CDE'})

Arguments:

  • title: String - The title of the event.
  • details: Object - The event's details.
  • options: Object - Options specific to the saved event.

Returns: Promise

  • fulfilled: String - Updated event's ID.
  • rejected: Error

Create calendar event with alarms

Alarm options:

Property Type Description iOS Android
date Date or Number If a Date is given, an alarm will be set with an absolute date. If a Number is given, an alarm will be set with a relative offset (in minutes) from the start date.
structuredLocation Object The location to trigger an alarm.

Alarm structuredLocation properties:

Property Type Description iOS Android
title String The title of the location.
proximity String A value indicating how a location-based alarm is triggered. Possible values: enter, leave, none.
radius Number A minimum distance from the core location that would trigger the calendar event's alarm.
coords Object The geolocation coordinates, as an object with latitude and longitude properties

Example with date:

RNCalendarEvents.saveEvent('title', {
  location: 'location',
  notes: 'notes',
  startDate: '2016-08-19T19:26:00.000Z',
  endDate: '2017-08-19T19:26:00.000Z',
  alarms: [{
    date: -1 // or absolute date - iOS Only
  }]
})

Example with structuredLocation (iOS Only):

RNCalendarEvents.saveEvent('title', {
  location: 'location',
  notes: 'notes',
  startDate: '2016-08-19T19:26:00.000Z',
  endDate: '2017-08-19T19:26:00.000Z',
  alarms: [{
    structuredLocation: {
      title: 'title',
      proximity: 'enter',
      radius: 500,
      coords: {
        latitude: 30.0000,
        longitude: 97.0000
      }
    }
  }]
})

Example with recurrence:

RNCalendarEvents.saveEvent('title', {
  location: 'location',
  notes: 'notes',
  startDate: '2016-08-19T19:26:00.000Z',
  endDate: '2017-08-29T19:26:00.000Z',
  alarms: [{
    date: -1 // or absolute date - iOS Only
  }],
  recurrenceRule: {
    frequency: 'daily'
    interval: 2,
    endDate: '2017-08-29T19:26:00.000Z'
  }
})

removeEvent

Removes calendar event.

RNCalendarEvents.removeEvent(id, options)

Arguments:

  • id: String - The id of the event to remove.
  • options: Object - Options specific to event removal.

Returns: Promise

  • fulfilled: Bool - Successful
  • rejected: Error

removeFutureEvents (iOS Only)

Removes future (recurring) calendar events.

RNCalendarEvents.removeFutureEvents(id)

Arguments:

  • id: String - The id of the event to remove.

Returns: Promise

  • fulfilled: Bool - Successful
  • rejected: Error

findCalendars

Finds all the calendars on the device.

RNCalendarEvents.findCalendars()

Returns: Promise

  • fulfilled: Array - A list of known calendars on the device
  • rejected: Error

About

React Native Module for iOS and Android Calendar Events

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 57.7%
  • Objective-C 38.9%
  • JavaScript 2.7%
  • Ruby 0.7%