Skip to content

Commit 4db3ecd

Browse files
committed
Add event handler types
1 parent d1feacb commit 4db3ecd

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

index.d.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
declare module 'react-native-voip-push-notification' {
2-
export type Events =
3-
'notification' |
4-
'register'|
5-
'didLoadWithEvents';
2+
export type NativeEvents = {
3+
register: 'RNVoipPushRemoteNotificationsRegisteredEvent';
4+
notification: 'RNVoipPushRemoteNotificationReceivedEvent';
5+
didLoadWithEvents: 'RNVoipPushDidLoadWithEvents';
6+
}
7+
8+
export type Events = keyof NativeEvents;
9+
export type EventsPayload = {
10+
register: string,
11+
notification: object,
12+
didLoadWithEvents: Array<InitialEvent>,
13+
}
14+
15+
export type InitialEvent = {
16+
[Event in Events]: { name: NativeEvents[Event], data: EventsPayload[Event] }
17+
}[Events];
618

719
export default class RNVoipPushNotification {
8-
static addEventListener(type: Events, handler: (args: any) => void): void
20+
static RNVoipPushRemoteNotificationsRegisteredEvent: NativeEvents['register']
21+
static RNVoipPushRemoteNotificationReceivedEvent: NativeEvents['notification']
22+
static RNVoipPushDidLoadWithEvents: NativeEvents['didLoadWithEvents']
23+
24+
static addEventListener<Event extends Events>(
25+
type: Event,
26+
handler: (args: EventsPayload[Event]) => void,
27+
): void
28+
static removeEventListener(type: Events): void
29+
930
static registerVoipToken(): void;
1031
static onVoipNotificationCompleted(uuid: string): void;
11-
static removeEventListener(type: Events): void
1232
}
1333
}

0 commit comments

Comments
 (0)