-
Notifications
You must be signed in to change notification settings - Fork 767
/
Copy pathNativeCommandsSender.ts
118 lines (95 loc) · 4.19 KB
/
NativeCommandsSender.ts
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { NativeModules } from 'react-native';
import { Notification } from '../DTO/Notification';
import { NotificationCompletion } from '../interfaces/NotificationCompletion';
import { NotificationPermissions } from '../interfaces/NotificationPermissions';
import { NotificationCategory } from '../interfaces/NotificationCategory';
import { NotificationChannel } from '../interfaces/NotificationChannel';
interface NativeCommandsModule {
getInitialNotification(): Promise<Object>;
postLocalNotification(notification: Notification, id: number): void;
requestPermissions(options?: RequestPermissionsOptions[]): void;
abandonPermissions(): void;
refreshToken(): void;
registerPushKit(): void;
getBadgeCount(): Promise<number>;
setBadgeCount(count: number): void;
cancelLocalNotification(notificationId: string): void;
cancelAllLocalNotifications(): void;
isRegisteredForRemoteNotifications(): Promise<boolean>;
checkPermissions(): Promise<NotificationPermissions>;
removeDeliveredNotifications(identifiers: Array<string>): void;
removeAllDeliveredNotifications(): void;
getDeliveredNotifications(): Promise<Notification[]>;
setCategories(categories: [NotificationCategory?]): void;
finishPresentingNotification(notificationId: string, callback: NotificationCompletion): void;
finishHandlingAction(notificationId: string): void;
setNotificationChannel(notificationChannel: NotificationChannel): void;
finishHandlingBackgroundAction(notificationId: string, backgroundFetchResult: string): void;
}
export type RequestPermissionsOptions = 'ProvidesAppNotificationSettings' | 'Provisional';
export class NativeCommandsSender {
private readonly nativeCommandsModule: NativeCommandsModule;
constructor() {
this.nativeCommandsModule = NativeModules.RNBridgeModule;
}
postLocalNotification(notification: Notification, id: number) {
return this.nativeCommandsModule.postLocalNotification(notification, id);
}
getInitialNotification(): Promise<Object> {
return this.nativeCommandsModule.getInitialNotification();
}
requestPermissions(options?: RequestPermissionsOptions[]) {
return this.nativeCommandsModule.requestPermissions(options);
}
abandonPermissions() {
return this.nativeCommandsModule.abandonPermissions();
}
refreshToken() {
this.nativeCommandsModule.refreshToken();
}
registerPushKit() {
return this.nativeCommandsModule.registerPushKit();
}
setCategories(categories: [NotificationCategory?]) {
this.nativeCommandsModule.setCategories(categories);
}
getBadgeCount(): Promise<number> {
return this.nativeCommandsModule.getBadgeCount();
}
setBadgeCount(count: number) {
this.nativeCommandsModule.setBadgeCount(count);
}
cancelLocalNotification(notificationId: string) {
this.nativeCommandsModule.cancelLocalNotification(notificationId);
}
cancelAllLocalNotifications() {
this.nativeCommandsModule.cancelAllLocalNotifications();
}
isRegisteredForRemoteNotifications(): Promise<any> {
return this.nativeCommandsModule.isRegisteredForRemoteNotifications();
}
checkPermissions() {
return this.nativeCommandsModule.checkPermissions();
}
removeAllDeliveredNotifications() {
return this.nativeCommandsModule.removeAllDeliveredNotifications();
}
removeDeliveredNotifications(identifiers: Array<string>) {
return this.nativeCommandsModule.removeDeliveredNotifications(identifiers);
}
public getDeliveredNotifications(): Promise<Notification[]> {
return this.nativeCommandsModule.getDeliveredNotifications();
}
finishPresentingNotification(notificationId: string, notificationCompletion: NotificationCompletion): void {
this.nativeCommandsModule.finishPresentingNotification(notificationId, notificationCompletion);
}
finishHandlingAction(notificationId: string): void {
this.nativeCommandsModule.finishHandlingAction(notificationId);
}
setNotificationChannel(notificationChannel: NotificationChannel) {
this.nativeCommandsModule.setNotificationChannel(notificationChannel);
}
finishHandlingBackgroundAction(notificationId: string, backgroundFetchResult: string): void {
this.nativeCommandsModule.finishHandlingBackgroundAction(notificationId, backgroundFetchResult);
}
}