UNPKG

@kode-frontend/react-native-push-notification

Version:
168 lines (156 loc) 7.25 kB
import * as effector from 'effector'; import React, { ReactNode } from 'react'; import { FirebaseMessagingTypes } from '@react-native-firebase/messaging'; import { TriggerNotification, InitialNotification, IOSNotificationAttachment, AndroidBigPictureStyle } from '@notifee/react-native'; type TPushSettings = { fcmToken: string | null; isNotificationEnabled: boolean; needFirstRequestPermission: boolean; }; declare const $pushSettings: effector.Store<TPushSettings>; declare const updateFcmToken: effector.Event<string | null>; declare const enablePush: effector.Event<void>; declare const disablePush: effector.Event<void>; declare const skipRequestPermissions: effector.Event<void>; declare const resetPushSettings: effector.Event<void>; declare const $pushEnabled: effector.Store<boolean>; declare const $fcmToken: effector.Store<string | null>; declare const $needFirstRequestPermission: effector.Store<boolean>; type TUseRegisterDeviceParams = { isNotificationsAvailable: boolean; updatePushToken: (token: string, config: { onSuccess: () => void; }) => void; }; type TRegisterParams = { force?: boolean; }; declare const useRegisterDevice: ({ isNotificationsAvailable, updatePushToken, }: TUseRegisterDeviceParams) => { registerDevice: ({ force }?: TRegisterParams) => Promise<void>; }; declare const useUnregisterDevice: () => { unregister: () => Promise<void>; }; type TParams = { onFailEnabledPush: () => void; }; declare const usePushAvailable: ({ onFailEnabledPush }: TParams) => { enabled: boolean; isLoading: boolean; changeNotificationEnabled: (state: boolean) => Promise<void>; }; type TPushNotificationServiceProps = { children: ReactNode; channelId: string; channelName: string; smallIcon?: string; }; declare const PushNotificationService: ({ channelId, channelName, children, }: TPushNotificationServiceProps) => React.JSX.Element; type TPushNotificationBody<T = Record<string, any>> = { id?: string; title?: string; body?: string; data?: T; }; type TFirebaseRemoteMessage = FirebaseMessagingTypes.RemoteMessage & Partial<TPushNotificationBody>; type TOptions = { /** * Condition under which the handler should be called */ condition: (notification: TPushNotificationBody) => boolean; /** * Event when a push is received while the application is running */ onReceived: (notification: TPushNotificationBody) => void; /** * Event when an application is opened by clicking on a push */ onOpened: (notification: TPushNotificationBody) => void; }; declare function usePush({ condition, onReceived, onOpened }: TOptions): null; /** * Checks for permissions to send notifications */ declare function hasPermission(): Promise<boolean>; /** * Request permissions to receive push notifications */ declare function requestPermission(): Promise<boolean>; /** * Checks and request permissions to receive push notifications */ declare function checkPermission(): Promise<boolean>; /** * Receives scheduled local push notifications */ declare function getScheduledLocalNotifications(): Promise<TriggerNotification[]>; /** * Cancels all local pushes */ declare function cancelAllNotifications(): Promise<void>; /** * Cancels local push by id */ declare function cancelNotification(notificationId: string): Promise<void>; /** * Gets the initial remote push (from Firebase) */ declare function getInitialPush(): Promise<FirebaseMessagingTypes.RemoteMessage | null>; /** * Gets the initial local push */ declare function getInitialLocalPush(): Promise<InitialNotification | null>; /** * Gets the Firebase FCM-token for push notifications */ declare const getToken: () => Promise<string | null>; /** * Removes the FCM-token in Firebase. The device will not be able to receive push notifications */ declare const removeToken: () => Promise<void>; /** * Go to notification settings */ declare const openSettings: (channelId?: string) => Promise<void>; /** * Set the number on the badge (iOS) */ declare const setApplicationIconBadgeNumber: (number: number) => void; /** * Increases the number on the badge (iOS) */ declare const incrementApplicationIconBadgeNumber: () => void; /** * Decreases the number on the badge (iOS) */ declare const decrementApplicationIconBadgeNumber: () => void; /** * Retrieves attachment on iOS from remoteMessage */ declare const getIosAttachment: (message: TFirebaseRemoteMessage) => Promise<IOSNotificationAttachment[]>; /** * Retrieves attachment on Android from remoteMessage */ declare const getAndroidAttachment: (message: FirebaseMessagingTypes.RemoteMessage) => Promise<AndroidBigPictureStyle | undefined>; declare const mapRemotePushToLocalPush: (remotePush: FirebaseMessagingTypes.RemoteMessage) => TPushNotificationBody; declare const utils_cancelAllNotifications: typeof cancelAllNotifications; declare const utils_cancelNotification: typeof cancelNotification; declare const utils_checkPermission: typeof checkPermission; declare const utils_decrementApplicationIconBadgeNumber: typeof decrementApplicationIconBadgeNumber; declare const utils_getAndroidAttachment: typeof getAndroidAttachment; declare const utils_getInitialLocalPush: typeof getInitialLocalPush; declare const utils_getInitialPush: typeof getInitialPush; declare const utils_getIosAttachment: typeof getIosAttachment; declare const utils_getScheduledLocalNotifications: typeof getScheduledLocalNotifications; declare const utils_getToken: typeof getToken; declare const utils_hasPermission: typeof hasPermission; declare const utils_incrementApplicationIconBadgeNumber: typeof incrementApplicationIconBadgeNumber; declare const utils_mapRemotePushToLocalPush: typeof mapRemotePushToLocalPush; declare const utils_openSettings: typeof openSettings; declare const utils_removeToken: typeof removeToken; declare const utils_requestPermission: typeof requestPermission; declare const utils_setApplicationIconBadgeNumber: typeof setApplicationIconBadgeNumber; declare namespace utils { export { utils_cancelAllNotifications as cancelAllNotifications, utils_cancelNotification as cancelNotification, utils_checkPermission as checkPermission, utils_decrementApplicationIconBadgeNumber as decrementApplicationIconBadgeNumber, utils_getAndroidAttachment as getAndroidAttachment, utils_getInitialLocalPush as getInitialLocalPush, utils_getInitialPush as getInitialPush, utils_getIosAttachment as getIosAttachment, utils_getScheduledLocalNotifications as getScheduledLocalNotifications, utils_getToken as getToken, utils_hasPermission as hasPermission, utils_incrementApplicationIconBadgeNumber as incrementApplicationIconBadgeNumber, utils_mapRemotePushToLocalPush as mapRemotePushToLocalPush, utils_openSettings as openSettings, utils_removeToken as removeToken, utils_requestPermission as requestPermission, utils_setApplicationIconBadgeNumber as setApplicationIconBadgeNumber }; } export { $fcmToken, $needFirstRequestPermission, $pushEnabled, $pushSettings, PushNotificationService, disablePush, enablePush, utils as pushService, resetPushSettings, skipRequestPermissions, updateFcmToken, usePush, usePushAvailable, useRegisterDevice, useUnregisterDevice };