Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

React Native Module for iOS and Android Calendar Events

License

NotificationsYou must be signed in to change notification settings

KTDevelopment/react-native-calendar-events

 
 

npmnpmnpm

A React Native module to help access and save events to iOS and Android calendars.

Getting started

This package assumes that you already have a React Native project or are familiar with React Native. If not, checkout the official documentation for more details about getting started withReact Native.

Support

versionreact-native version
2.0.0+0.60.0+
pre 2.0.0+0.40.0+

For 0.59-, you should usejetify -r

Installation

$ npm install --save react-native-calendar-events# --- or ---$ yarn add react-native-calendar-events

Don't forget going into theios directory to execute apod install.

🆘 Manual linking

Because this package targets React Native 0.60.0+, you will probably don't need to link it manually. Otherwise if it's not the case, follow this additional instructions:

👀 See manual linking instructions

iOS

Add this line to yourios/Podfile file, then runpod install.

target'YourAwesomeProject'do#  pod'RNCalendarEvents', :path =>'../node_modules/react-native-calendar-events'end

Android

1 - Add the following lines toandroid/settings.gradle:

include':react-native-calendar-events'project(':react-native-calendar-events').projectDir=newFile(rootProject.projectDir,'../node_modules/react-native-calendar-events/android')

2 - Add the implementation line to the dependencies inandroid/app/build.gradle:

dependencies {// ...  implementation project(':react-native-calendar-events')}

3 - Add the import and link the package inMainApplication.java:

importcom.calendarevents.RNCalendarEventsPackage;// <- add the RNCalendarEventsPackage importpublicclassMainApplicationextendsApplicationimplementsReactApplication {// …@OverrideprotectedList<ReactPackage>getPackages() {@SuppressWarnings("UnnecessaryLocalVariable")List<ReactPackage>packages =newPackageList(this).getPackages();// …packages.add(newRNCalendarEventsPackage());returnpackages;  }// …}

iOS specific instructions

AddRNCalendarEvents, as well asEventKit.framework to project libraries if not already done.

Setting up privacy usage descriptions may also be required depending on which iOS version is supported. This involves updating the Property List,Info.plist, with the corresponding key for the EKEventStore api.Info.plist reference.

For updating theInfo.plist key/value via XCode, add aPrivacy - Calendars Usage Description key with a usage description as the value. Resulting change toInfo.plist should look something like:

<key>NSCalendarsUsageDescription</key><string>This app requires access to the calendar</string>

API

The following API allows for interacting with both iOS and Android device calendars. See the full list of availableevent fields.

importRNCalendarEventsfrom"react-native-calendar-events";

checkPermissions

Get calendar authorization status.You may check for the default read/write access with no argument, or read-only access on Android by passing boolean true. iOS is always read/write.

RNCalendarEvents.checkPermissions((readOnly=false));

Returns:Promise

  • fulfilled: String -denied,restricted,authorized orundetermined
  • rejected: Error

requestPermissions

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

RNCalendarEvents.requestPermissions((readOnly=false));

(readOnly is for Android only, see below)

Android note: this is necessary for targeted SDK of >=23.iOS note: This method will crash, if you didn't updateInfo.plist. Follow carefully installation instruction.

Returns:Promise

  • fulfilled: String -denied,restricted,authorized orundetermined
  • rejected: Error

Read-OnlyrequestPermissions (Android only)

⚠️ Note that to restrict to read-only usage on Android (iOS is always read/write) you will need to alter the included Android permissionsas theAndroidManifest.xml is merged during the Android build.

You do that by altering your AndroidManifest.xml to "remove" the WRITE_CALENDAR permission with an entry like so:

<manifestxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"  ><!-- ...-->  <uses-permissiontools:node="remove"android:name="android.permission.WRITE_CALENDAR" />

findCalendars

Finds all the calendars on the device.

RNCalendarEvents.findCalendars();

Returns:Promise

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

saveCalendar

Create a calendar.

RNCalendarEvents.saveCalendar(calendar);

⚠️ When you want to save a calendar, you need to use a valid source (find usingfindCalendars).

Arguments:

Returns:Promise

  • fulfilled: The id of the created calendar
  • rejected: Error

removeCalendar

Removes a calendar.

RNCalendarEvents.removeCalendar(id);

Arguments:

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

Returns:Promise

  • fulfilled: Bool - Successful
  • 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: String - The start date of the range of events fetched.
  • endDate: String - 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 or updates a calendar event. -wiki guide

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. Note that on Android,saveEvent accepts an additional optionsync (boolean) to prevent syncing issues.

Returns:Promise

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

To update an event, the eventid must be defined. -wiki guide

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

Example for saveEvent

Creating events is fairly straightforward. Hopefully the following explanation can help.

BasicsaveEvent

For both iOS and Android the pattern is simple; the event needs atitle as well as astartDate andendDate. TheendDate should also be a date later than thestartDate.

RNCalendarEvents.saveEvent('Title of event',{startDate:'2016-08-19T19:26:00.000Z',endDate:'2017-08-19T19:26:00.000Z'})
Specify a calendarsaveEvent

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 thecalendarId. This will ensure your event is saved to an expected calendar.

RNCalendarEvents.saveEvent('Title of event',{calendarId:'141',startDate:'2016-08-19T19:26:00.000Z',endDate:'2017-08-19T19:26:00.000Z'})
Additional fields withsaveEvent

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 foundin the wiki.

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

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

Event fields

PropertyTypeDescriptioniOSAndroid
id*StringUnique id for the calendar event.
calendarId**StringUnique id for the calendar where the event will be saved. Defaults to the device's default calendar.
titleStringThe title for the calendar event.
startDateStringThe start date of the calendar event in ISO format.
endDateStringThe end date of the calendar event in ISO format.
allDayBoolIndicates whether the event is an all-day
event.
recurrenceStringThe simple recurrence frequency of the calendar eventdaily,weekly,monthly,yearly or none.
recurrenceRule **ObjectThe events recurrence settings.
occurrenceDate*StringThe original occurrence date of an event if it is part of a recurring series.
isDetachedBoolIndicates whether an event is a detached instance of a repeating event.
urlStringThe url associated with the calendar event.
locationStringThe location associated with the calendar event.
structuredLocationStringThe structuredLocation associated with the calendar event.
notesStringThe notes associated with the calendar event.
descriptionStringThe description associated with the calendar event.
alarmsArrayThe alarms associated with the calendar event, as an array of alarm objects.
attendees*ArrayThe attendees of the event, including the organizer.
calendar*ObjectThe calendar containing the event.
skipAndroidTimezoneBoolSkip the process of setting automatic timezone on android
timeZoneStringThe time zone associated with the event

Calendar

PropertyTypeDescriptioniOSAndroid
idStringUnique calendar ID.
titleStringThe calendar’s title.
typeStringThe calendar’s type.
sourceStringThe source object representing the account to which this calendar belongs.
isPrimary*BoolIndicates if the calendar is assigned as primary.
allowsModifications*BoolIndicates if the calendar allows events to be written, edited or removed.
color*StringThe color assigned to the calendar represented as a hex value.
allowedAvailabilities*ArrayThe event availability settings supported by the calendar.

Attendees

PropertyTypeDescriptioniOSAndroid
nameStringThe name of the attendee.
email*StringThe email address of the attendee.
phone*StringThe phone number of the attendee.

Recurrence rule

PropertyTypeDescriptioniOSAndroid
frequencyStringEvent recurring frequency. Allowed values aredaily,weekly,monthly,yearly.
endDateStringEvent recurring end date. This overrides occurrence.
occurrenceNumberNumber of event occurrences.
intervalNumberThe interval between events of this recurrence.

Alarms

PropertyTypeDescriptioniOSAndroid
dateString or NumberIf a String 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.
structuredLocationObjectThe location to trigger an alarm.

Alarm structuredLocation

PropertyTypeDescriptioniOSAndroid
titleStringThe title of the location.
proximityStringA value indicating how a location-based alarm is triggered. Possible values:enter,leave,none.
radiusNumberA minimum distance from the core location that would trigger the calendar event's alarm.
coordsObjectThe geolocation coordinates, as an object with latitude and longitude properties

Options

PropertyTypeDescriptioniOSAndroid
exceptionDateStringThe start date of a recurring event's exception instance. Used for updating single event in a recurring series
futureEventsBoolIftrue the update will span all future events. Iffalse it only update the single instance.

Calendar options

PropertyTypeDescriptioniOSAndroid
titleStringThe calendar title (required)
colorStringThe calendar color (required)
entityTypeString'event' or 'reminder' (required)
nameStringThe calendar name (required)
accessLevelStringDefines how the event shows up for others when the calendar is shareddoc(required)'contributor', 'editor', 'freebusy', 'override', 'owner', 'read', 'respond', 'root'
ownerAccountStringThe owner account for this calendar, based on the calendar feeddoc(required)
sourceObjectThe calendar Account source (required)
source.nameStringThe Account name (required)
source.typeStringThe Account type
source.isLocalAccountBoolThe source (required ifsource.type is not used)

*Read only, ** _Write only

Troubleshooting

These are some common issues you may run into while usingreact-native-calendar-events library.If you encounter something that is not listed here, trysearching in GitHub issues ofreact-native-calendar-events.

After saving an event, it disappear form the calendar

This might be related to a sync issue.You need to be sure that the event you saved is matching what your device will keep in sync.

For iOS, you might have not all event synced. You might need to update this iOS settings inSettings >Calendar >Sync >All Events. If that's not enough, it might be worth checkingiOS iCloud sync documentation.
For Android, you can have a look toGoogle Calendar sync problems documentation.

Duplicated events after editing and saving an event

Another symptom of syncing issue. See the issue above.Note that on Android,saveEvent accepts an additional optionsync (boolean) to prevent syncing issues.

Wiki

Authors

See also the list ofcontributors who participated in this project.

License

This project is licensed under the MIT License - see theLICENSE.md file for details

Acknowledgments

Big thanks to all who have contributed, raised an issue or simply find use in this project. Cheers!

About

React Native Module for iOS and Android Calendar Events

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java52.7%
  • Objective-C38.8%
  • JavaScript6.8%
  • Ruby1.2%
  • Starlark0.5%

[8]ページ先頭

©2009-2025 Movatter.jp