Schedule local notifications from React Native on iOS and Android.
yarn add @guulabs/react-native-local-notifications
import {
scheduleNotification,
cancelScheduledNotifications,
cancelAllScheduledNotifications,
} from '@guulabs/react-native-local-notifications';
// ...
const id = await scheduleNotification(
{
title: 'Title',
body: 'This is the body of the local notification.',
},
{
timestamp: Date.now() + 5000,
}
);
// Cancel a list of notification ids
await cancelScheduledNotifications([id, "another_id1", "another_id2"]);
// Cancel all
await cancelAllScheduledNotifications();
Set a custom icon and set an accent color.
const id = await scheduleNotification(
{
title: 'Title',
body: 'This is the body of the local notification.',
android: {
smallIcon: 'ic_launcher',
color: '#0000ff',
}
},
{
timestamp: Date.now() + 5000,
}
);
Param name | Type | Default | Description |
---|---|---|---|
title | string |
- | Title of the local notification. |
body | string |
- | The body for the local notification. |
android | { smallIcon: string, color: string } |
{ smallIcon: 'ic_launcher' } |
Use smallIcon to set a custom resource name (drawable or mipmap) for the notification icon on Android. Use color to set a hex accent color for the notification on Android. |
timestamp | number |
- | The date in milliseconds when the local notfication should be dispatched. |
This library was desinged to minimize the JS footprint, it contains only a few fuctions defined on the JS side. If your use case requires more than sending some simple local notifications, I strongly advive to use Notifee.
- 🏋️♂️ Follow me on Twitter @GutuCristian or LinkedIn for updates.
- ⭐️ Star this repo.
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
Made with create-react-native-library