index.d.ts 5.26 KB
Newer Older
1 2
declare module "react-native-fcm" {

Libin Lu's avatar
Libin Lu committed
3
    type FCMEventType = "FCMTokenRefreshed" | "FCMNotificationReceived" | 'FCMDirectChannelConnectionChanged';
4 5 6
    export module FCMEvent {
        const RefreshToken = "FCMTokenRefreshed";
        const Notification = "FCMNotificationReceived";
Libin Lu's avatar
Libin Lu committed
7
        const DirectChannelConnectionChanged: 'FCMDirectChannelConnectionChanged'
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
    }

    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";
    }

28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
    export enum NotificationCategoryOption {
        CustomDismissAction = 'UNNotificationCategoryOptionCustomDismissAction',
        AllowInCarPlay = 'UNNotificationCategoryOptionAllowInCarPlay',
        PreviewsShowTitle = 'UNNotificationCategoryOptionHiddenPreviewsShowTitle',
        PreviewsShowSubtitle = 'UNNotificationCategoryOptionHiddenPreviewsShowSubtitle',
        None = 'UNNotificationCategoryOptionNone'
    }

    export enum NotificationActionOption {
        AuthenticationRequired = 'UNNotificationActionOptionAuthenticationRequired',
        Destructive = 'UNNotificationActionOptionDestructive',
        Foreground = 'UNNotificationActionOptionForeground',
        None = 'UNNotificationActionOptionNone'
    }

    export enum NotificationActionType {
        Default = 'UNNotificationActionTypeDefault',
        TextInput = 'UNNotificationActionTypeTextInput',
    }

Daniel Prado's avatar
Daniel Prado committed
48
    export interface Notification {
49 50 51 52 53 54 55 56
        collapse_key: string;
        opened_from_tray: boolean;
        from: string;
        notification: {
            title?: string
            body: string;
            icon: string;
        };
57 58 59 60 61 62 63 64
        fcm: {
            action?: string;
            tag?: string;
            icon?: string;
            color?: string;
            body: string;
            title?: string;
        };
65
        local_notification?: boolean;
66
        _notificationType: string;
67 68
        _actionIdentifier?: string;
        _userText?: string;
69
        finish(type?: string): void;
Daniel Prado's avatar
Daniel Prado committed
70
        [key: string]: any;
71 72 73
    }

    export interface LocalNotification {
74
        id?: string;
75 76 77 78
        title?: string;
        body: string;
        icon?: string;
        vibrate?: number;
Baptiste MORELLE's avatar
Baptiste MORELLE committed
79
        sound?: string;
80
        big_text?: string;
81 82
        sub_text?: string;
        color?: string;
83
        large_icon?: string;
84 85 86
        priority?: string;
        show_in_foreground?: boolean;
        click_action?: string;
Libin Lu's avatar
Libin Lu committed
87
        badge?: number;
88 89 90 91 92
        number?: number;
        ticker?: string;
        auto_cancel?: boolean;
        group?: string;
        picture?: string;
Libin Lu's avatar
Libin Lu committed
93 94
        ongoing?: boolean;
        lights?: boolean;
Daniel Prado's avatar
Daniel Prado committed
95
        [key: string]: any;
96 97
    }

Daniel Prado's avatar
Daniel Prado committed
98
    export interface ScheduleLocalNotification extends LocalNotification {
99
        id: string;
100 101
        fire_date: number;
        repeat_interval?: "week" | "day" | "hour"
102 103
    }

104 105 106 107
    export interface Subscription {
        remove(): void;
    }

108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
    export interface NotificationAction {
        type: NotificationActionType;
        id: string;
        title?: string;
        textInputButtonTitle?: string;
        textInputPlaceholder?: string;
        options: NotificationActionOption | NotificationActionOption[];
    }

    export interface NotificationCategory {
        id: string;
        actions: NotificationAction[];
        intentIdentifiers: string[];
        hiddenPreviewsBodyPlaceholder?: string;
        options?: NotificationCategoryOption | NotificationCategoryOption[];
    }

125
    export class FCM {
Libin Lu's avatar
Libin Lu committed
126
        static requestPermissions(): Promise<void>;
127 128
        static getFCMToken(): Promise<string>;
        static on(event: "FCMTokenRefreshed", handler: (token: string) => void): Subscription;
129
        static on(event: "FCMNotificationReceived", handler: (notification: Notification) => void): Subscription;
130 131
        static subscribeToTopic(topic: string): void;
        static unsubscribeFromTopic(topic: string): void;
132 133
        static getInitialNotification(): Promise<Notification>;
        static presentLocalNotification(notification: LocalNotification): void;
134

Libin Lu's avatar
Libin Lu committed
135
        static scheduleLocalNotification(schedule: ScheduleLocalNotification): void;
136
        static getScheduledLocalNotifications(): Promise<LocalNotification>;
137 138 139 140 141 142 143 144 145 146

        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;
Libin Lu's avatar
Libin Lu committed
147 148 149 150

        static enableDirectChannel(): void
        static isDirectChannelEstablished(): Promise<boolean>
        static getAPNSToken(): Promise<string>
151 152

        static setNotificationCategories(categories: NotificationCategory[]): void;
153 154 155 156
    }

    export default FCM;
}