rn-calendar-event
v1.0.0
Published
readonly android calendar and events apiicalendar apicalendar api
Downloads
0
Maintainers
Readme
rn-calendar-event
A React Native Turbo Module for accessing Android Calendar Provider calendars and events.
Android only.
Features
- Request calendar permissions
- Get all calendars
- Get a calendar by ID
- Get all events
- Get events within a date range
- Filter events by calendar IDs
- Get an event by ID
Installation
npm install rn-calendar-eventUsage
import * as NativeCalendarEvent from 'rn-calendar-event';Request Permission
Before accessing calendars or events, request the required Android calendar permissions:
const granted = await NativeCalendarEvent.requestCalendarPermission();
console.log('Permission granted:', granted);Get All Calendars
const calendars = await NativeCalendarEvent.getAllCalendars();
console.log(calendars);Get Calendar by ID
const calendar = await NativeCalendarEvent.getCalendarById('1');
if (calendar) {
console.log(calendar.title);
}Returns null when the calendar cannot be found.
Get All Events
const events = await NativeCalendarEvent.getAllEvents();
console.log(events);Get Events by Date Range
startDate and endDate must be ISO 8601 date strings.
const events = await NativeCalendarEvent.getAllEventsByRange(
'2026-08-01T00:00:00.000Z',
'2026-08-31T23:59:59.999Z',
['1', '2'],
);
console.log(events);Pass an empty array to query events from all calendars:
const events = await NativeCalendarEvent.getAllEventsByRange(
'2026-08-01T00:00:00.000Z',
'2026-08-31T23:59:59.999Z',
[],
);Get Event by ID
const event = await NativeCalendarEvent.getEventById('123');
if (event) {
console.log(event.title);
}Returns null when the event cannot be found.
API
requestPermission()
requestPermission(): Promise<boolean>;Requests the Android calendar permissions required by the library.
getAllCalendars()
getAllCalendars(): Promise<Calendar[]>;Returns all calendars available through the Android Calendar Provider.
getCalendarById()
getCalendarById(calendarId: string): Promise<Calendar | null>;Returns a calendar by its ID.
getAllEvents()
getAllEvents(): Promise<Event[]>;Returns all events available through the Android Calendar Provider.
getAllEventsByRange()
getAllEventsByRange(
startDate: string,
endDate: string,
calendarIds: Array<string>,
): Promise<Event[]>;Returns events within the specified date range.
startDate— UTC ISO 8601 start dateendDate— UTC ISO 8601 end datecalendarIds— calendar IDs to query; use[]for all calendars
Example:
const events = await NativeCalendarEvent.getAllEventsByRange(
new Date('2026-08-01T00:00:00.000Z').toISOString(),
new Date('2026-08-31T23:59:59.999Z').toISOString(),
['1', '2'],
);getEventById()
getEventById(eventId: string): Promise<Event | null>;Returns an event by its ID.
Types
Calendar
export interface Calendar {
/** Unique calendar ID. */
id: string;
/** The calendar's title. */
title: string;
/** The calendar's type. */
type: string;
/** The source object representing the account to which this calendar belongs. */
source: string;
/** Indicates if the calendar is assigned as primary. */
isPrimary: boolean;
/** Indicates if the calendar allows events to be written, edited or removed. */
allowsModifications: boolean;
/** The color assigned to the calendar represented as a hex value. */
color: string;
/** The event availability settings supported by the calendar. */
allowedAvailabilities: string[];
}Event
export interface Event {
id: string;
/** The title for the calendar event. */
title: string;
/** The start date of the calendar event in ISO format. */
startDate: string;
/** The end date of the calendar event in ISO format. */
endDate?: string;
/** The ID of the calendar where the event belongs. */
calendarId?: string;
/** Indicates whether the event is an all-day event. */
allDay?: boolean;
/** The location associated with the calendar event. */
location?: string;
/** The simple recurrence frequency of the calendar event. */
recurrence?: string;
/** The event description. */
description?: string;
/** The availability of the event. */
availability?: string;
/** The original event ID. */
originalId?: string;
/** The synchronization ID. */
syncId?: string;
}Permissions
The library uses Android's Calendar Provider and requires calendar permissions.
Add the required permissions to AndroidManifest.xml:
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />Request permission before querying calendar data:
import * as NativeCalendarEvent from 'rn-calendar-event';
const granted = await NativeCalendarEvent.requestPermission();
if (!granted) {
console.log('Calendar permission was not granted');
return;
}
const calendars = await NativeCalendarEvent.getAllCalendars();
const events = await NativeCalendarEvent.getAllEvents();Example
A simple calendar viewer:
import React, { useState } from 'react';
import { Button, Text, View } from 'react-native';
import * as NativeCalendarEvent from 'rn-calendar-event';
export default function App() {
const [message, setMessage] = useState('');
const loadCalendars = async () => {
try {
const granted = await NativeCalendarEvent.requestPermission();
if (!granted) {
setMessage('Calendar permission was not granted');
return;
}
const calendars = await NativeCalendarEvent.getAllCalendars();
setMessage(`Found ${calendars.length} calendars`);
} catch (error) {
setMessage(String(error));
}
};
return (
<View>
<Button title="Load Calendars" onPress={loadCalendars} />
<Text>{message}</Text>
</View>
);
}Contributing
License
MIT
Made with create-react-native-library
