react-native-notification-badge
Version:
A notification badge count manager for React Native
52 lines (51 loc) • 2.59 kB
TypeScript
export declare type BadgeSetting = 'enabled' | 'disabled' | 'notSupported' | 'unknown';
export declare type NotificationPermission = 'badge' | 'alert' | 'sound' | 'carPlay' | 'criticalAlert' | 'providesAppNotificationSettings' | 'provisional' | 'announcement';
/**
* **Asynchronously sets the Badge count.**
*
* Note: If no notification permissions have been granted yet, this will also ask the user for notification permissions (only `[.badge]`), so request permissions before calling this using a library like [react-native-permissions](https://github.com/react-native-community/react-native-permissions)
* @param badgeCount The new badge count to set
* @example
* await setBadgeCount(2)
*/
export declare function setBadgeCount(badgeCount: number): Promise<void>;
/**
* **Asynchronously returns the current Badge count.**
*
* Note: If no notification permissions have been granted yet, this will also ask the user for notification permissions (only `[.badge]`), so request permissions before calling this using a library like [react-native-permissions](https://github.com/react-native-community/react-native-permissions)
* @example
* const badgeCount = await getBadgeCount()
*/
export declare function getBadgeCount(): Promise<number>;
/**
* Same as [`getBadgeCount`](#getbadgecount), but synchronously.
* @example
* const badgeCount = getBadgeCountSync()
*/
export declare function getBadgeCountSync(): number;
/**
* Asynchronously gets the current state of the "Notification Badge" permission setting.
* @example
* const permission = await getNotificationBadgeSetting()
* if (permission === 'enabled') {
* await setBadgeCount(5)
* } else {
* console.log("Badge permission has not yet been granted. I'll ask the user later")
* }
*/
export declare function getNotificationBadgeSetting(): Promise<BadgeSetting>;
/**
* Asynchronously request the user to grant the specified permissions.
* @param permissions The array of permissions to grant
* @example
* const granted = await requestNotificationPermissions(['alert', 'badge', 'sound'])
*/
export declare function requestNotificationPermissions(permissions: NotificationPermission[]): Promise<boolean>;
/**
* Remove all notification with the given Thread ID from the User's Notification Center
* @param threadId The Thread ID to filter notifications by which shall be removed
* @returns The count of the notifications that were removed
* @example
* await removeNotificationsWithThreadId('group-chat-1')
*/
export declare function removeNotificationsWithThreadId(threadId: string): Promise<number>;