@trycourier/courier-react-native 2.0.0-beta2 → 2.0.0-beta4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/ios/CourierReactNativeModule.m +43 -4
  2. package/ios/CourierReactNativeModule.swift +87 -79
  3. package/ios/CourierReactNativeViewManager.m +1 -3
  4. package/ios/CourierReactNativeViewManager.swift +4 -17
  5. package/lib/commonjs/hooks/CourierProvider.js +258 -0
  6. package/lib/commonjs/hooks/CourierProvider.js.map +1 -0
  7. package/lib/commonjs/index.js +205 -12
  8. package/lib/commonjs/index.js.map +1 -1
  9. package/lib/commonjs/models/CourierAuthenticationListener.js +21 -0
  10. package/lib/commonjs/models/CourierAuthenticationListener.js.map +1 -0
  11. package/lib/commonjs/models/CourierPushListener.js +15 -0
  12. package/lib/commonjs/models/CourierPushListener.js.map +1 -0
  13. package/lib/commonjs/views/CourierInboxView.js +4 -2
  14. package/lib/commonjs/views/CourierInboxView.js.map +1 -1
  15. package/lib/module/hooks/CourierProvider.js +245 -0
  16. package/lib/module/hooks/CourierProvider.js.map +1 -0
  17. package/lib/module/index.js +166 -13
  18. package/lib/module/index.js.map +1 -1
  19. package/lib/module/models/CourierAuthenticationListener.js +13 -0
  20. package/lib/module/models/CourierAuthenticationListener.js.map +1 -0
  21. package/lib/module/models/CourierPushListener.js +8 -0
  22. package/lib/module/models/CourierPushListener.js.map +1 -0
  23. package/lib/module/views/CourierInboxView.js +4 -2
  24. package/lib/module/views/CourierInboxView.js.map +1 -1
  25. package/lib/typescript/hooks/CourierProvider.d.ts +57 -0
  26. package/lib/typescript/hooks/CourierProvider.d.ts.map +1 -0
  27. package/lib/typescript/index.d.ts +82 -1
  28. package/lib/typescript/index.d.ts.map +1 -1
  29. package/lib/typescript/models/CourierAuthenticationListener.d.ts +7 -0
  30. package/lib/typescript/models/CourierAuthenticationListener.d.ts.map +1 -0
  31. package/lib/typescript/models/CourierPushListener.d.ts +7 -0
  32. package/lib/typescript/models/CourierPushListener.d.ts.map +1 -0
  33. package/lib/typescript/views/CourierInboxView.d.ts +4 -2
  34. package/lib/typescript/views/CourierInboxView.d.ts.map +1 -1
  35. package/package.json +1 -1
  36. package/src/hooks/CourierProvider.tsx +355 -0
  37. package/src/index.tsx +186 -13
  38. package/src/models/CourierAuthenticationListener.tsx +19 -0
  39. package/src/models/CourierPushListener.tsx +13 -0
  40. package/src/views/CourierInboxView.tsx +5 -4
@@ -0,0 +1,355 @@
1
+ import React, { createContext, ReactNode, useContext, useEffect, useState } from 'react';
2
+ import { InboxMessage } from 'src/models/InboxMessage';
3
+ import Courier, { CourierPushListener, CourierInboxListener, CourierAuthenticationListener, iOSForegroundPresentationOptions } from '..';
4
+
5
+ let authListener: CourierAuthenticationListener | undefined = undefined
6
+ let pushListener: CourierPushListener | undefined = undefined
7
+ let inboxListener: CourierInboxListener | undefined = undefined
8
+
9
+ interface CourierAuthContext {
10
+ start: () => void;
11
+ isLoading: boolean;
12
+ error?: string;
13
+ userId?: string;
14
+ signIn: (props: { accessToken: string; clientKey?: string; userId: string }) => Promise<void>;
15
+ signOut: () => Promise<void>;
16
+ }
17
+
18
+ interface CourierPushContext {
19
+ start: () => void;
20
+ delivered: any;
21
+ clicked: any;
22
+ tokens: {
23
+ apns?: string;
24
+ fcm?: string;
25
+ };
26
+ notificationPermissionStatus?: string;
27
+ requestNotificationPermission: () => Promise<void>;
28
+ }
29
+
30
+ interface CourierInboxContext {
31
+ start: () => void;
32
+ isLoading: boolean;
33
+ error?: string;
34
+ messages: InboxMessage[];
35
+ unreadMessageCount: number;
36
+ totalMessageCount: number;
37
+ canPaginate: boolean;
38
+ iOSForegroundPresentationOptions: (options: iOSForegroundPresentationOptions[]) => void;
39
+ setPaginationLimit: (limit: number) => void;
40
+ fetchNextPageOfMessages: () => Promise<InboxMessage[]>;
41
+ refresh: () => Promise<void>;
42
+ isRefreshing: boolean;
43
+ readAllMessages: () => Promise<void>;
44
+ readMessage: (messageId: string) => Promise<void>;
45
+ unreadMessage: (messageId: string) => Promise<void>;
46
+ }
47
+
48
+ interface CourierContext {
49
+ auth: CourierAuthContext;
50
+ push: CourierPushContext;
51
+ inbox: CourierInboxContext;
52
+ }
53
+
54
+ const CourierContext = createContext<CourierContext | undefined>(undefined);
55
+
56
+ export const CourierProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
57
+
58
+ // Auth
59
+ const [auth_userId, auth_setUserId] = useState<string | undefined>(undefined);
60
+ const [auth_isLoading, auth_setIsLoading] = useState<boolean>(false);
61
+ const [auth_error, auth_setError] = useState<string | undefined>(undefined);
62
+
63
+ // Push
64
+ const [push_pushNotificationDelivered, inbox_setPushNotificationDelivered] = useState<any>(undefined);
65
+ const [push_pushNotificationClicked, inbox_setPushNotificationClicked] = useState<any>(undefined);
66
+ const [push_apnsToken, push_setApnsToken] = useState<string | undefined>(undefined);
67
+ const [push_fcmToken, push_setFcmToken] = useState<string | undefined>(undefined);
68
+ const [push_notificationPermission, push_setNotificationPermission] = useState<string | undefined>(undefined);
69
+
70
+ // Inbox
71
+ const [inbox_isLoading, inbox_setIsLoading] = useState<boolean>(false);
72
+ const [inbox_isRefreshing, inbox_setIsRefreshing] = useState<boolean>(false);
73
+ const [inbox_error, inbox_setError] = useState<string | undefined>(undefined);
74
+ const [inbox_messages, inbox_setMessages] = useState<InboxMessage[]>([]);
75
+ const [inbox_unreadMessageCount, inbox_setUnreadMessageCount] = useState<number>(0);
76
+ const [inbox_totalMessageCount, inbox_setTotalMessageCount] = useState<number>(0);
77
+ const [inbox_canPaginate, inbox_setCanPaginate] = useState<boolean>(false);
78
+
79
+ useEffect(() => {
80
+
81
+ // Get the initial values
82
+ const userId = Courier.shared.userId;
83
+ auth_setUserId(userId);
84
+
85
+ // Permissions
86
+ syncNotificationPermissions();
87
+
88
+ // Push tokens
89
+ syncTokens();
90
+
91
+ }, []);
92
+
93
+ useEffect(() => {
94
+
95
+ return () => {
96
+ authListener?.remove();
97
+ pushListener?.remove();
98
+ inboxListener?.remove();
99
+ }
100
+
101
+ }, []);
102
+
103
+ const startAuth = () => {
104
+
105
+ if (!authListener) {
106
+
107
+ authListener = Courier.shared.addAuthenticationListener({
108
+ onUserChanged: (userId) => auth_setUserId(userId)
109
+ });
110
+
111
+ }
112
+
113
+ }
114
+
115
+ const startPush = () => {
116
+
117
+ if (!pushListener) {
118
+
119
+ pushListener = Courier.shared.addPushNotificationListener({
120
+ onPushNotificationDelivered: (push) => inbox_setPushNotificationDelivered(push),
121
+ onPushNotificationClicked: (push) => inbox_setPushNotificationClicked(push)
122
+ });
123
+
124
+ }
125
+
126
+ }
127
+
128
+ const startInbox = () => {
129
+
130
+ if (!inboxListener) {
131
+
132
+ inboxListener = Courier.shared.addInboxListener({
133
+ onInitialLoad: () => {
134
+ inbox_setIsLoading(true);
135
+ inbox_setError(undefined);
136
+ },
137
+ onError: (error) => {
138
+ inbox_setIsLoading(false);
139
+ inbox_setError(error);
140
+ },
141
+ onMessagesChanged: (messages, unreadMessageCount, totalMessageCount, canPaginate) => {
142
+ inbox_setIsLoading(false);
143
+ inbox_setError(undefined);
144
+ inbox_setMessages(messages);
145
+ inbox_setUnreadMessageCount(unreadMessageCount);
146
+ inbox_setTotalMessageCount(totalMessageCount);
147
+ inbox_setCanPaginate(canPaginate);
148
+ }
149
+ });
150
+
151
+ }
152
+
153
+ }
154
+
155
+ const signIn = async (props: { accessToken: string, clientKey?: string, userId: string }): Promise<void> => {
156
+
157
+ auth_setIsLoading(true);
158
+ auth_setError(undefined);
159
+
160
+ try {
161
+ await Courier.shared.signIn(props);
162
+ } catch (error) {
163
+ auth_setError(error as string);
164
+ }
165
+
166
+ auth_setIsLoading(false);
167
+
168
+ };
169
+
170
+ const signOut = async (): Promise<void> => {
171
+
172
+ auth_setIsLoading(true);
173
+ auth_setError(undefined);
174
+
175
+ try {
176
+ await Courier.shared.signOut();
177
+ } catch (error) {
178
+ auth_setError(error as string);
179
+ }
180
+
181
+ auth_setIsLoading(false);
182
+
183
+ };
184
+
185
+ const syncNotificationPermissions = async () => {
186
+
187
+ const status = await Courier.shared.getNotificationPermissionStatus();
188
+ push_setNotificationPermission(status);
189
+
190
+ }
191
+
192
+ const syncTokens = () => {
193
+
194
+ // APNS
195
+ const apnsToken = Courier.shared.apnsToken;
196
+ push_setApnsToken(apnsToken);
197
+
198
+ const fcmToken = Courier.shared.fcmToken;
199
+ push_setFcmToken(fcmToken);
200
+
201
+ }
202
+
203
+ const requestNotificationPermission = async () => {
204
+ const status = await Courier.shared.requestNotificationPermission();
205
+ push_setNotificationPermission(status);
206
+ };
207
+
208
+ const iOSForegroundPresentationOptions = (options: iOSForegroundPresentationOptions[]) => {
209
+ Courier.shared.iOSForegroundPresentationOptions({
210
+ options: options,
211
+ });
212
+ }
213
+
214
+ const setPaginationLimit = (limit: number) => {
215
+ Courier.shared.setInboxPaginationLimit({ limit });
216
+ };
217
+
218
+ const fetchNextPageOfMessages = (): Promise<InboxMessage[]> => {
219
+ return Courier.shared.fetchNextPageOfMessages();
220
+ };
221
+
222
+ const refresh = async () => {
223
+ inbox_setIsRefreshing(true);
224
+ await Courier.shared.refreshInbox();
225
+ inbox_setIsRefreshing(false);
226
+ };
227
+
228
+ const readAllMessages = () => {
229
+
230
+ // Skip if no user is found
231
+ if (!Courier.shared.userId) {
232
+ return Promise.resolve();
233
+ }
234
+
235
+ // Read the messages
236
+ return Courier.shared.readAllInboxMessages();
237
+
238
+ };
239
+
240
+ const readMessage = (messageId: string) => {
241
+ return Courier.shared.readMessage({ messageId });
242
+ };
243
+
244
+ const unreadMessage = (messageId: string) => {
245
+ return Courier.shared.unreadMessage({ messageId });
246
+ };
247
+
248
+ return (
249
+ <CourierContext.Provider value={{
250
+ auth: {
251
+ start: startAuth,
252
+ isLoading: auth_isLoading,
253
+ error: auth_error,
254
+ userId: auth_userId,
255
+ signIn,
256
+ signOut
257
+ },
258
+ push: {
259
+ start: startPush,
260
+ delivered: push_pushNotificationDelivered,
261
+ clicked: push_pushNotificationClicked,
262
+ tokens: {
263
+ fcm: push_fcmToken,
264
+ apns: push_apnsToken,
265
+ },
266
+ notificationPermissionStatus: push_notificationPermission,
267
+ requestNotificationPermission,
268
+ },
269
+ inbox: {
270
+ start: startInbox,
271
+ isLoading: inbox_isLoading,
272
+ error: inbox_error,
273
+ messages: inbox_messages,
274
+ unreadMessageCount: inbox_unreadMessageCount,
275
+ totalMessageCount: inbox_totalMessageCount,
276
+ canPaginate: inbox_canPaginate,
277
+ iOSForegroundPresentationOptions,
278
+ setPaginationLimit,
279
+ fetchNextPageOfMessages,
280
+ refresh,
281
+ isRefreshing: inbox_isRefreshing,
282
+ readAllMessages,
283
+ readMessage,
284
+ unreadMessage,
285
+ }
286
+ }}>
287
+ {children}
288
+ </CourierContext.Provider>
289
+ );
290
+
291
+ };
292
+
293
+ // Auth Hook
294
+ export const useCourierAuth = (): CourierAuthContext => {
295
+
296
+ const context = useContext(CourierContext);
297
+
298
+ if (!context) {
299
+ throw new Error('useCourierAuth must be used within an CourierProvider');
300
+ }
301
+
302
+ context.auth.start();
303
+
304
+ return context.auth;
305
+
306
+ };
307
+
308
+ // Push Hook
309
+ export const useCourierPush = (): CourierPushContext => {
310
+
311
+ const context = useContext(CourierContext);
312
+
313
+ if (!context) {
314
+ throw new Error('useCourierPush must be used within an CourierProvider');
315
+ }
316
+
317
+ context.push.start();
318
+
319
+ return context.push;
320
+
321
+ };
322
+
323
+ interface UseCourierInboxProps {
324
+ paginationLimit?: number;
325
+ iOS?: {
326
+ foregroundPresentationOptions?: iOSForegroundPresentationOptions[]
327
+ }
328
+ }
329
+
330
+ // Inbox Hook
331
+ export const useCourierInbox = (props: UseCourierInboxProps = {}): CourierInboxContext => {
332
+
333
+ const context = useContext(CourierContext);
334
+
335
+ if (!context) {
336
+ throw new Error('useCourierInbox must be used within an CourierProvider');
337
+ }
338
+
339
+ // Set the initial pagination limit if needed
340
+ const limit = props.paginationLimit;
341
+ if (limit) {
342
+ context.inbox?.setPaginationLimit(limit);
343
+ }
344
+
345
+ // Set the presentation options
346
+ const options = props.iOS?.foregroundPresentationOptions;
347
+ if (options) {
348
+ context.inbox?.iOSForegroundPresentationOptions(options);
349
+ }
350
+
351
+ context.inbox?.start();
352
+
353
+ return context.inbox;
354
+
355
+ };
package/src/index.tsx CHANGED
@@ -3,11 +3,22 @@ import {
3
3
  NativeEventEmitter,
4
4
  EmitterSubscription,
5
5
  Platform,
6
+ DeviceEventEmitter,
6
7
  } from 'react-native';
7
8
 
9
+ // Imports
8
10
  import { CourierInboxListener } from './models/CourierInboxListener';
11
+ import { CourierPushListener } from './models/CourierPushListener';
12
+ import { CourierAuthenticationListener } from './models/CourierAuthenticationListener';
9
13
  import { InboxMessage } from './models/InboxMessage';
14
+
15
+ // Exports
10
16
  export { CourierInboxView } from './views/CourierInboxView';
17
+ export { CourierProvider, useCourierAuth, useCourierPush, useCourierInbox } from './hooks/CourierProvider';
18
+ export { CourierInboxListener } from './models/CourierInboxListener';
19
+ export { CourierPushListener } from './models/CourierPushListener';
20
+ export { CourierAuthenticationListener } from './models/CourierAuthenticationListener';
21
+ export type iOSForegroundPresentationOptions = 'sound' | 'badge' | 'list' | 'banner';
11
22
 
12
23
  const LINKING_ERROR =
13
24
  `The package '@trycourier/courier-react-native' doesn't seem to be linked. Make sure: \n\n` +
@@ -32,6 +43,9 @@ const CourierEventEmitter = new NativeEventEmitter(
32
43
 
33
44
  class Courier {
34
45
 
46
+ readonly PUSH_NOTIFICATION_CLICKED = 'pushNotificationClicked';
47
+ readonly PUSH_NOTIFICATION_DELIVERED = 'pushNotificationDelivered';
48
+
35
49
  private static _sharedInstance: Courier;
36
50
  private _isDebugging = false;
37
51
  private debugListener: EmitterSubscription | undefined;
@@ -57,16 +71,7 @@ class Courier {
57
71
 
58
72
  private async setDefaults() {
59
73
  this.setIsDebugging(__DEV__);
60
- // try {
61
- // await Promise.all([
62
- // this.setIsDebugging(__DEV__),
63
- // // this.iOSForegroundPresentationOptions({
64
- // // options: ['sound', 'badge', 'list', 'banner'],
65
- // // }),
66
- // ]);
67
- // } catch (error) {
68
- // console.log(error);
69
- // }
74
+ this.iOSForegroundPresentationOptions({ options: ['sound', 'badge', 'list', 'banner'] });
70
75
  }
71
76
 
72
77
  /**
@@ -99,12 +104,143 @@ class Courier {
99
104
  return this._isDebugging;
100
105
  }
101
106
 
107
+ /**
108
+ * TODO
109
+ * @param props
110
+ * @returns
111
+ */
112
+ public iOSForegroundPresentationOptions(props: { options: iOSForegroundPresentationOptions[] }): string {
113
+
114
+ // Only works on iOS
115
+ if (Platform.OS !== 'ios') return 'unsupported';
116
+
117
+ const normalizedParams = Array.from(new Set(props.options));
118
+ return CourierReactNativeModules.iOSForegroundPresentationOptions({
119
+ options: normalizedParams,
120
+ });
121
+
122
+ }
123
+
124
+ /**
125
+ * Sets the current Apple Push Notification Service (APNS) token
126
+ * using Courier token management apis
127
+ * @example const apnsToken = await Courier.apnsToken
128
+ */
129
+ get apnsToken(): string | undefined {
130
+ if (Platform.OS !== 'ios') return undefined;
131
+ return CourierReactNativeModules.getApnsToken();
132
+ }
133
+
134
+ /**
135
+ * Sets the current Firebase Cloud Messaging (FCM) token
136
+ * using Courier token management apis
137
+ * @example const fcmToken = await Courier.fcmToken
138
+ */
139
+ get fcmToken(): string | undefined {
140
+ return CourierReactNativeModules.getFcmToken();
141
+ }
142
+
143
+ /**
144
+ * Sets the current Firebase Cloud Messaging (FCM) token
145
+ * using Courier token management apis
146
+ * @example await setFcmToken('asdf...asdf')
147
+ */
148
+ public setFcmToken(props: { token: string }): Promise<void> {
149
+ return CourierReactNativeModules.setFcmToken(props.token);
150
+ }
151
+
152
+ /**
153
+ * Gets notification permission status at a system level.
154
+ * @example const permissionStatus = await Courier.getNotificationPermissionStatus()
155
+ */
156
+ public getNotificationPermissionStatus(): Promise<string> {
157
+ return CourierReactNativeModules.getNotificationPermissionStatus();
158
+ }
159
+
160
+ /**
161
+ * Requests notification permission status at a system level.
162
+ * Returns the string associated with the permission status.
163
+ * Will return the current status and will not present a popup
164
+ * if the user has already been asked for permission.
165
+ * @example const permissionStatus = await Courier.requestNotificationPermission()
166
+ */
167
+ public requestNotificationPermission(): Promise<string> {
168
+ return CourierReactNativeModules.requestNotificationPermission();
169
+ }
170
+
171
+ /**
172
+ * @example
173
+ TODO
174
+ * @returns function that can be used to unsubscribe from registered listeners
175
+ */
176
+ public addPushNotificationListener(props: { onPushNotificationClicked?: (push: any) => void, onPushNotificationDelivered?: (push: any) => void }): CourierPushListener {
177
+
178
+ const pushListener = new CourierPushListener();
179
+
180
+ if (Platform.OS === 'android') {
181
+
182
+ if (props.onPushNotificationClicked) {
183
+ pushListener.onNotificationClickedListener = DeviceEventEmitter.addListener(this.PUSH_NOTIFICATION_CLICKED, (event: any) => {
184
+ try {
185
+ props.onPushNotificationClicked!(JSON.parse(event));
186
+ } catch (error) {
187
+ console.log(error);
188
+ }
189
+ });
190
+ }
191
+
192
+ if (props.onPushNotificationDelivered) {
193
+ pushListener.onNotificationDeliveredListener = DeviceEventEmitter.addListener(this.PUSH_NOTIFICATION_DELIVERED, (event: any) => {
194
+ try {
195
+ props.onPushNotificationDelivered!(JSON.parse(event));
196
+ } catch (error) {
197
+ console.log(error);
198
+ }
199
+ });
200
+ }
201
+
202
+ }
203
+
204
+ if (Platform.OS === 'ios') {
205
+
206
+ if (props.onPushNotificationClicked) {
207
+ pushListener.onNotificationClickedListener = CourierEventEmitter.addListener(this.PUSH_NOTIFICATION_CLICKED, (event: any) => {
208
+ try {
209
+ props.onPushNotificationClicked!(JSON.parse(event));
210
+ } catch (error) {
211
+ console.log(error);
212
+ }
213
+ });
214
+ }
215
+
216
+ if (props.onPushNotificationDelivered) {
217
+ pushListener.onNotificationDeliveredListener = CourierEventEmitter.addListener(this.PUSH_NOTIFICATION_DELIVERED, (event: any) => {
218
+ try {
219
+ props.onPushNotificationDelivered!(JSON.parse(event));
220
+ } catch (error) {
221
+ console.log(error);
222
+ }
223
+ });
224
+ }
225
+
226
+ }
227
+
228
+ // When listener is registered
229
+ // Attempt to fetch the last message that was clicked
230
+ // This is needed for when the app is killed and the
231
+ // user launched the app by clicking on a notifications
232
+ CourierReactNativeModules.registerPushNotificationClickedOnKilledState();
233
+
234
+ return pushListener
235
+
236
+ }
237
+
102
238
  /**
103
239
  * Returns the current user id stored in local native storage
104
240
  * @example const userId = await Courier.userId
105
241
  */
106
- get userId(): Promise<string | undefined> {
107
- return CourierReactNativeModules.getUserId();
242
+ get userId(): string | undefined {
243
+ return CourierReactNativeModules.getUserId() ?? undefined
108
244
  }
109
245
 
110
246
  /**
@@ -127,6 +263,43 @@ class Courier {
127
263
  return CourierReactNativeModules.signIn(props.accessToken, props.clientKey ?? null, props.userId);
128
264
  }
129
265
 
266
+ /**
267
+ * TODO
268
+ * @param props
269
+ * @returns
270
+ */
271
+ public signOut(): Promise<void> {
272
+ return CourierReactNativeModules.signOut();
273
+ }
274
+
275
+ /**
276
+ * TODO
277
+ * @param props
278
+ * @returns
279
+ */
280
+ public addAuthenticationListener(props: { onUserChanged: (userId?: string) => void }): CourierAuthenticationListener {
281
+
282
+ const authListener = new CourierAuthenticationListener();
283
+
284
+ authListener.onUserChanged = CourierEventEmitter.addListener('courierAuthUserChanged', event => {
285
+ props.onUserChanged(event)
286
+ });
287
+
288
+ authListener.listenerId = CourierReactNativeModules.addAuthenticationListener();
289
+
290
+ return authListener;
291
+
292
+ }
293
+
294
+ /**
295
+ * TODO
296
+ * @param props
297
+ * @returns
298
+ */
299
+ public removeAuthenticationListener(props: { listenerId: string }): string {
300
+ return CourierReactNativeModules.removeAuthenticationListener(props.listenerId);
301
+ }
302
+
130
303
  /**
131
304
  * TODO
132
305
  * @param props
@@ -187,7 +360,7 @@ class Courier {
187
360
  });
188
361
  }
189
362
 
190
- inboxListener.listenerId = CourierReactNativeModules.addInboxListener(null);
363
+ inboxListener.listenerId = CourierReactNativeModules.addInboxListener();
191
364
 
192
365
  return inboxListener;
193
366
 
@@ -0,0 +1,19 @@
1
+ import { EmitterSubscription } from "react-native";
2
+ import Courier from "..";
3
+
4
+ export class CourierAuthenticationListener {
5
+
6
+ public listenerId?: string
7
+ public onUserChanged?: EmitterSubscription
8
+
9
+ public remove() {
10
+
11
+ if (this.listenerId) {
12
+ Courier.shared.removeInboxListener({ listenerId: this.listenerId });
13
+ }
14
+
15
+ this.onUserChanged?.remove();
16
+
17
+ }
18
+
19
+ }
@@ -0,0 +1,13 @@
1
+ import { EmitterSubscription } from "react-native";
2
+
3
+ export class CourierPushListener {
4
+
5
+ public onNotificationClickedListener?: EmitterSubscription
6
+ public onNotificationDeliveredListener?: EmitterSubscription
7
+
8
+ public remove() {
9
+ this.onNotificationClickedListener?.remove();
10
+ this.onNotificationDeliveredListener?.remove();
11
+ }
12
+
13
+ }
@@ -5,8 +5,10 @@ import { InboxAction } from "src/models/InboxAction";
5
5
  import { InboxMessage } from "src/models/InboxMessage";
6
6
 
7
7
  type CourierInboxViewProps = {
8
- lightTheme?: CourierInboxTheme;
9
- darkTheme?: CourierInboxTheme;
8
+ theme?: {
9
+ light?: CourierInboxTheme,
10
+ dark?: CourierInboxTheme
11
+ };
10
12
  onClickInboxMessageAtIndex?: (message: InboxMessage, index: number) => void;
11
13
  onClickInboxActionForMessageAtIndex?: (action: InboxAction, message: InboxMessage, index: number) => void;
12
14
  onScrollInbox?: (offsetY: number, offsetX: number) => void;
@@ -73,8 +75,7 @@ export const CourierInboxView = (props: CourierInboxViewProps) => {
73
75
 
74
76
  return (
75
77
  <CourierInbox
76
- lightTheme={props.lightTheme}
77
- darkTheme={props.darkTheme}
78
+ theme={props.theme ?? { light: undefined, dark: undefined }}
78
79
  onClickInboxMessageAtIndex={onClickInboxMessageAtIndex}
79
80
  onClickInboxActionForMessageAtIndex={onClickInboxActionForMessageAtIndex}
80
81
  onScrollInbox={onScrollInbox}