index.d.ts 2.75 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
declare module "react-native-fcm" {

    type FCMEventType = "FCMTokenRefreshed" | "FCMNotificationReceived";
    export module FCMEvent {
        const RefreshToken = "FCMTokenRefreshed";
        const Notification = "FCMNotificationReceived";
    }

    export module RemoteNotificationResult {
        const NewData = "UIBackgroundFetchResultNewData";
        const NoData = "UIBackgroundFetchResultNoData";
        const ResultFailed = "UIBackgroundFetchResultFailed";
    }

    export module WillPresentNotificationResult {
        const All = "UNNotificationPresentationOptionAll";
        const None = "UNNotificationPresentationOptionNone";
    }

    export module NotificationType {
        const Remote = "remote_notification";
        const NotificationResponse = "notification_response";
        const WillPresent = "will_present_notification";
        const Local = "local_notification";
    }

27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
  export interface Notification {
        collapse_key: string;
        opened_from_tray: boolean;
        from: string;
        notification: {
            title?: string
            body: string;
            icon: string;
        };
        _notificationType: string;
        finish(type?: string): void;
    }

    export interface LocalNotification {
        title?: string;
        body: string;
        icon?: string;
        vibrate?: number;
Baptiste MORELLE's avatar
Baptiste MORELLE committed
45
        sound?: string;
46 47 48 49 50 51 52 53 54 55
        big_text?: string;
        large_icon?: string;
        priority?: string
    }

    export interface ScheduleLocalNotification extends LocalNotification{
        id: string;
        fire_date: number
    }

56 57 58 59 60 61 62 63
    export interface Subscription {
        remove(): void;
    }

    export class FCM {
        static requestPermissions(): void;
        static getFCMToken(): Promise<string>;
        static on(event: "FCMTokenRefreshed", handler: (token: string) => void): Subscription;
64
        static on(event: "FCMNotificationReceived", handler: (notification: Notification) => void): Subscription;
65 66
        static subscribeToTopic(topic: string): void;
        static unsubscribeFromTopic(topic: string): void;
67 68
        static getInitialNotification(): Promise<Notification>;
        static presentLocalNotification(notification: LocalNotification): void;
69

70 71
        static scheduleLocalNotification(schedule: LocalNotification): void;
        static getScheduledLocalNotifications(): Promise<LocalNotification>;
72 73 74 75 76 77 78 79 80 81 82 83 84 85

        static removeAllDeliveredNotifications(): void;
        static removeDeliveredNotification(id: string): void;

        static cancelAllLocalNotifications(): void;
        static cancelLocalNotification(id: string): string;

        static setBadgeNumber(badge: number): void;
        static getBadgeNumber(): Promise<number>;
        static send(id: string, data: any): void;
    }

    export default FCM;
}