@trycourier/courier-react-native 2.0.0-beta1 → 2.0.0-beta3

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 (47) hide show
  1. package/ios/CourierReactNative-Bridging-Header.h +1 -0
  2. package/ios/CourierReactNative.xcodeproj/project.pbxproj +5 -3
  3. package/ios/CourierReactNative.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  4. package/ios/CourierReactNative.xcodeproj/project.xcworkspace/xcuserdata/mike.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  5. package/ios/CourierReactNative.xcodeproj/xcuserdata/mike.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  6. package/ios/CourierReactNativeDelegate.h +18 -0
  7. package/ios/CourierReactNativeDelegate.m +125 -0
  8. package/ios/CourierReactNativeModule.m +54 -2
  9. package/ios/CourierReactNativeModule.swift +104 -70
  10. package/ios/CourierReactNativeViewManager.m +1 -3
  11. package/ios/CourierReactNativeViewManager.swift +14 -18
  12. package/lib/commonjs/hooks/useCourier.js +224 -0
  13. package/lib/commonjs/hooks/useCourier.js.map +1 -0
  14. package/lib/commonjs/index.js +215 -13
  15. package/lib/commonjs/index.js.map +1 -1
  16. package/lib/commonjs/models/CourierAuthenticationListener.js +21 -0
  17. package/lib/commonjs/models/CourierAuthenticationListener.js.map +1 -0
  18. package/lib/commonjs/models/CourierPushListener.js +15 -0
  19. package/lib/commonjs/models/CourierPushListener.js.map +1 -0
  20. package/lib/commonjs/views/CourierInboxView.js +4 -2
  21. package/lib/commonjs/views/CourierInboxView.js.map +1 -1
  22. package/lib/module/hooks/useCourier.js +213 -0
  23. package/lib/module/hooks/useCourier.js.map +1 -0
  24. package/lib/module/index.js +188 -14
  25. package/lib/module/index.js.map +1 -1
  26. package/lib/module/models/CourierAuthenticationListener.js +13 -0
  27. package/lib/module/models/CourierAuthenticationListener.js.map +1 -0
  28. package/lib/module/models/CourierPushListener.js +8 -0
  29. package/lib/module/models/CourierPushListener.js.map +1 -0
  30. package/lib/module/views/CourierInboxView.js +4 -2
  31. package/lib/module/views/CourierInboxView.js.map +1 -1
  32. package/lib/typescript/hooks/useCourier.d.ts +52 -0
  33. package/lib/typescript/hooks/useCourier.d.ts.map +1 -0
  34. package/lib/typescript/index.d.ts +96 -2
  35. package/lib/typescript/index.d.ts.map +1 -1
  36. package/lib/typescript/models/CourierAuthenticationListener.d.ts +7 -0
  37. package/lib/typescript/models/CourierAuthenticationListener.d.ts.map +1 -0
  38. package/lib/typescript/models/CourierPushListener.d.ts +7 -0
  39. package/lib/typescript/models/CourierPushListener.d.ts.map +1 -0
  40. package/lib/typescript/views/CourierInboxView.d.ts +4 -2
  41. package/lib/typescript/views/CourierInboxView.d.ts.map +1 -1
  42. package/package.json +1 -1
  43. package/src/hooks/useCourier.tsx +291 -0
  44. package/src/index.tsx +208 -15
  45. package/src/models/CourierAuthenticationListener.tsx +19 -0
  46. package/src/models/CourierPushListener.tsx +13 -0
  47. package/src/views/CourierInboxView.tsx +5 -4
@@ -1,2 +1,3 @@
1
+ #import <React/RCTBridgeModule.h>
1
2
  #import <React/RCTViewManager.h>
2
3
  #import <React/RCTEventEmitter.h>
@@ -7,8 +7,7 @@
7
7
  objects = {
8
8
 
9
9
  /* Begin PBXBuildFile section */
10
- 5E555C0D2413F4C50049A1A2 /* CourierReactNative.mm in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* CourierReactNative.mm */; };
11
- F4FF95D7245B92E800C19C63 /* CourierReactNative.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FF95D6245B92E800C19C63 /* CourierReactNative.swift */; };
10
+ F4FF95D7245B92E800C19C63 /* CourierReactNative.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FF95D6245B92E800C19C63 /* CourierReactNative.swift */; };
12
11
  /* End PBXBuildFile section */
13
12
 
14
13
  /* Begin PBXCopyFilesBuildPhase section */
@@ -25,6 +24,8 @@
25
24
 
26
25
  /* Begin PBXFileReference section */
27
26
  134814201AA4EA6300B7C361 /* libCourierReactNative.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libCourierReactNative.a; sourceTree = BUILT_PRODUCTS_DIR; };
27
+ 27960AF02A9E722F0076CE04 /* CourierReactNativeDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CourierReactNativeDelegate.h; sourceTree = "<group>"; };
28
+ 27960AF12A9E722F0076CE04 /* CourierReactNativeDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CourierReactNativeDelegate.m; sourceTree = "<group>"; };
28
29
  B3E7B5891CC2AC0600A0062D /* CourierReactNative.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CourierReactNative.mm; sourceTree = "<group>"; };
29
30
  F4FF95D5245B92E700C19C63 /* CourierReactNative-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CourierReactNative-Bridging-Header.h"; sourceTree = "<group>"; };
30
31
  F4FF95D6245B92E800C19C63 /* CourierReactNative.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourierReactNative.swift; sourceTree = "<group>"; };
@@ -52,6 +53,8 @@
52
53
  58B511D21A9E6C8500147676 = {
53
54
  isa = PBXGroup;
54
55
  children = (
56
+ 27960AF02A9E722F0076CE04 /* CourierReactNativeDelegate.h */,
57
+ 27960AF12A9E722F0076CE04 /* CourierReactNativeDelegate.m */,
55
58
  F4FF95D6245B92E800C19C63 /* CourierReactNative.swift */,
56
59
  B3E7B5891CC2AC0600A0062D /* CourierReactNative.mm */,
57
60
  F4FF95D5245B92E700C19C63 /* CourierReactNative-Bridging-Header.h */,
@@ -117,7 +120,6 @@
117
120
  buildActionMask = 2147483647;
118
121
  files = (
119
122
  F4FF95D7245B92E800C19C63 /* CourierReactNative.swift in Sources */,
120
- B3E7B58A1CC2AC0600A0062D /* CourierReactNative.mm in Sources */,
121
123
  );
122
124
  runOnlyForDeploymentPostprocessing = 0;
123
125
  };
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>IDEDidComputeMac32BitWarning</key>
6
+ <true/>
7
+ </dict>
8
+ </plist>
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>SchemeUserState</key>
6
+ <dict>
7
+ <key>CourierReactNative.xcscheme_^#shared#^_</key>
8
+ <dict>
9
+ <key>orderHint</key>
10
+ <integer>0</integer>
11
+ </dict>
12
+ </dict>
13
+ </dict>
14
+ </plist>
@@ -0,0 +1,18 @@
1
+ //
2
+ // CourierReactNativeDelegate.h
3
+ // courier-react-native
4
+ //
5
+ // Created by Michael Miller on 8/29/23.
6
+ //
7
+
8
+ #import "RCTAppDelegate.h"
9
+ #import <UIKit/UIKit.h>
10
+ #import <UserNotifications/UserNotifications.h>
11
+
12
+ NS_ASSUME_NONNULL_BEGIN
13
+
14
+ @interface CourierReactNativeDelegate : RCTAppDelegate<UNUserNotificationCenterDelegate>
15
+
16
+ @end
17
+
18
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,125 @@
1
+ //
2
+ // CourierReactNativeDelegate.m
3
+ // courier-react-native
4
+ //
5
+ // Created by Michael Miller on 10/7/22.
6
+ //
7
+
8
+ @import Courier_iOS;
9
+ #import "CourierReactNativeDelegate.h"
10
+ #pragma GCC diagnostic ignored "-Wprotocol"
11
+ #pragma clang diagnostic ignored "-Wprotocol"
12
+
13
+ @implementation CourierReactNativeDelegate
14
+
15
+ NSString *iosForegroundNotificationPresentationOptions = @"iosForegroundNotificationPresentationOptions";
16
+ NSUInteger notificationPresentationOptions = UNNotificationPresentationOptionNone;
17
+
18
+ - (id) init {
19
+
20
+ self = [super init];
21
+
22
+ if (self) {
23
+
24
+ // Register for remote notifications
25
+ UIApplication *app = [UIApplication sharedApplication];
26
+ [app registerForRemoteNotifications];
27
+
28
+ // Register notification center changes
29
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
30
+ center.delegate = self;
31
+
32
+ [[NSNotificationCenter defaultCenter]
33
+ addObserver:self
34
+ selector:@selector(notificationPresentationOptionsUpdate:)
35
+ name:iosForegroundNotificationPresentationOptions
36
+ object:nil
37
+ ];
38
+
39
+ }
40
+
41
+ return(self);
42
+
43
+ }
44
+
45
+ - (void) notificationPresentationOptionsUpdate:(NSNotification *) notification
46
+ {
47
+ if ([[notification name] isEqualToString:iosForegroundNotificationPresentationOptions])
48
+ {
49
+ NSDictionary *userInfo = notification.userInfo;
50
+ notificationPresentationOptions = ((NSNumber *) [userInfo objectForKey:@"options"]).unsignedIntegerValue;
51
+ }
52
+ }
53
+
54
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
55
+ {
56
+
57
+ UNNotificationContent *content = notification.request.content;
58
+ NSDictionary *message = content.userInfo;
59
+
60
+ [[Courier shared] trackNotificationWithMessage:message event:CourierPushEventDelivered completionHandler:^(NSError *error)
61
+ {
62
+ if (error != nil) {
63
+ [self log:error];
64
+ }
65
+ }
66
+ ];
67
+
68
+ NSDictionary *pushNotification = [Courier formatPushNotificationWithContent:content];
69
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotificationDelivered" object:nil userInfo:pushNotification];
70
+
71
+ completionHandler(notificationPresentationOptions);
72
+
73
+ }
74
+
75
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
76
+ {
77
+
78
+ UNNotificationContent *content = response.notification.request.content;
79
+ NSDictionary *message = content.userInfo;
80
+
81
+ [[Courier shared] trackNotificationWithMessage:message event:CourierPushEventClicked completionHandler:^(NSError *error)
82
+ {
83
+ if (error != nil) {
84
+ [self log:error];
85
+ }
86
+ }
87
+ ];
88
+
89
+ NSDictionary *pushNotification = [Courier formatPushNotificationWithContent:content];
90
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotificationClicked" object:nil userInfo:pushNotification];
91
+
92
+ dispatch_async(dispatch_get_main_queue(), ^{
93
+ completionHandler();
94
+ });
95
+
96
+ }
97
+
98
+ - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
99
+ {
100
+ [self log:error];
101
+ }
102
+
103
+ - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
104
+ {
105
+
106
+ [[Courier shared]
107
+ setAPNSToken:deviceToken
108
+ onSuccess:^()
109
+ {
110
+ // Empty
111
+ }
112
+ onFailure:^(NSError *error)
113
+ {
114
+ [self log:error];
115
+ }
116
+ ];
117
+
118
+ }
119
+
120
+ - (void)log: (NSError*)error {
121
+ NSString *err = [NSString stringWithFormat:@"%@", error];
122
+ [Courier log:err];
123
+ }
124
+
125
+ @end
@@ -2,6 +2,14 @@
2
2
 
3
3
  @interface RCT_EXTERN_MODULE(CourierReactNativeModule, NSObject)
4
4
 
5
+ RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
6
+ setDebugMode: (BOOL)isDebugging
7
+ )
8
+
9
+ RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
10
+ iOSForegroundPresentationOptions: (NSDictionary*)params
11
+ )
12
+
5
13
  RCT_EXTERN_METHOD(
6
14
  signIn: (NSString*)accessToken
7
15
  withClientKey: (NSString*)clientKey
@@ -15,8 +23,39 @@ RCT_EXTERN_METHOD(
15
23
  withRejecter: (RCTPromiseRejectBlock)reject
16
24
  )
17
25
 
26
+ RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
27
+ getUserId
28
+ )
29
+
30
+ RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
31
+ addAuthenticationListener
32
+ )
33
+
34
+ RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
35
+ removeAuthenticationListener: (NSString*)listenerId
36
+ )
37
+
38
+ RCT_EXTERN_METHOD(
39
+ getNotificationPermissionStatus: (RCTPromiseResolveBlock)resolve
40
+ withRejecter: (RCTPromiseRejectBlock)reject
41
+ )
42
+
43
+ RCT_EXTERN_METHOD(
44
+ requestNotificationPermission: (RCTPromiseResolveBlock)resolve
45
+ withRejecter: (RCTPromiseRejectBlock)reject
46
+ )
47
+
48
+ RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
49
+ getApnsToken
50
+ )
51
+
52
+ RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
53
+ getFcmToken
54
+ )
55
+
18
56
  RCT_EXTERN_METHOD(
19
- getUserId: (RCTPromiseResolveBlock)resolve
57
+ setFcmToken: (NSString*)token
58
+ withResolver: (RCTPromiseResolveBlock)resolve
20
59
  withRejecter: (RCTPromiseRejectBlock)reject
21
60
  )
22
61
 
@@ -38,7 +77,7 @@ RCT_EXTERN_METHOD(
38
77
  )
39
78
 
40
79
  RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
41
- addInboxListener: (NSString*)listenerId
80
+ addInboxListener
42
81
  )
43
82
 
44
83
  RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
@@ -50,4 +89,17 @@ RCT_EXTERN_METHOD(
50
89
  withRejecter: (RCTPromiseRejectBlock)reject
51
90
  )
52
91
 
92
+ RCT_EXTERN_METHOD(
93
+ fetchNextPageOfMessages: (RCTPromiseResolveBlock)resolve
94
+ withRejecter: (RCTPromiseRejectBlock)reject
95
+ )
96
+
97
+ RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
98
+ setInboxPaginationLimit: (double)limit
99
+ )
100
+
101
+ RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
102
+ registerPushNotificationClickedOnKilledState
103
+ )
104
+
53
105
  @end
@@ -4,9 +4,19 @@ import Courier_iOS
4
4
  class CourierReactNativeModule: RCTEventEmitter {
5
5
 
6
6
  private static let COURIER_ERROR_TAG = "Courier iOS SDK Error"
7
- internal static let COURIER_PUSH_NOTIFICATION_CLICKED_EVENT = "pushNotificationClicked"
8
- internal static let COURIER_PUSH_NOTIFICATION_DELIVERED_EVENT = "pushNotificationDelivered"
9
- private static let COURIER_PUSH_NOTIFICATION_DEBUG_LOG_EVENT = "courierDebugEvent"
7
+
8
+ class LogEvents {
9
+ internal static let DEBUG_LOG_EVENT = "courierDebugEvent"
10
+ }
11
+
12
+ class AuthEvents {
13
+ internal static let USER_CHANGED = "courierAuthUserChanged"
14
+ }
15
+
16
+ class PushEvents {
17
+ internal static let CLICKED_EVENT = "pushNotificationClicked"
18
+ internal static let DELIVERED_EVENT = "pushNotificationDelivered"
19
+ }
10
20
 
11
21
  class InboxEvents {
12
22
  internal static let INITIAL_LOADING = "inboxInitialLoad"
@@ -14,6 +24,7 @@ class CourierReactNativeModule: RCTEventEmitter {
14
24
  internal static let MESSAGES_CHANGED = "inboxMessagesChanged"
15
25
  }
16
26
 
27
+ private var authListeners = [String: CourierAuthenticationListener]()
17
28
  private var inboxListeners = [String: CourierInboxListener]()
18
29
 
19
30
  private var hasListeners = false
@@ -44,7 +55,7 @@ class CourierReactNativeModule: RCTEventEmitter {
44
55
  // setup listeners
45
56
  Courier.shared.logListener = { log in
46
57
  self.sendEvent(
47
- withName: CourierReactNativeModule.COURIER_PUSH_NOTIFICATION_DEBUG_LOG_EVENT,
58
+ withName: CourierReactNativeModule.LogEvents.DEBUG_LOG_EVENT,
48
59
  body: log
49
60
  )
50
61
  }
@@ -63,19 +74,25 @@ class CourierReactNativeModule: RCTEventEmitter {
63
74
  notificationCenter.addObserver(
64
75
  self,
65
76
  selector: #selector(pushNotificationClicked),
66
- name: Notification.Name(rawValue: CourierReactNativeModule.COURIER_PUSH_NOTIFICATION_CLICKED_EVENT),
77
+ name: Notification.Name(rawValue: CourierReactNativeModule.PushEvents.CLICKED_EVENT),
67
78
  object: nil
68
79
  )
69
80
 
70
81
  notificationCenter.addObserver(
71
82
  self,
72
83
  selector: #selector(pushNotificationDelivered),
73
- name: Notification.Name(rawValue: CourierReactNativeModule.COURIER_PUSH_NOTIFICATION_DELIVERED_EVENT),
84
+ name: Notification.Name(rawValue: CourierReactNativeModule.PushEvents.DELIVERED_EVENT),
74
85
  object: nil
75
86
  )
76
87
 
77
88
  }
78
89
 
90
+ @objc(setDebugMode:)
91
+ func setDebugMode(isDebugging: Bool) -> String {
92
+ Courier.shared.isDebugging = isDebugging
93
+ return String(describing: Courier.shared.isDebugging)
94
+ }
95
+
79
96
  private func sendMessage(name: String, message: [AnyHashable: Any]?) {
80
97
 
81
98
  guard let message = message else {
@@ -97,7 +114,7 @@ class CourierReactNativeModule: RCTEventEmitter {
97
114
 
98
115
  lastClickedMessage = notification.userInfo
99
116
  sendMessage(
100
- name: CourierReactNativeModule.COURIER_PUSH_NOTIFICATION_CLICKED_EVENT,
117
+ name: CourierReactNativeModule.PushEvents.CLICKED_EVENT,
101
118
  message: lastClickedMessage
102
119
  )
103
120
 
@@ -106,19 +123,23 @@ class CourierReactNativeModule: RCTEventEmitter {
106
123
  @objc private func pushNotificationDelivered(notification: Notification) {
107
124
 
108
125
  sendMessage(
109
- name: CourierReactNativeModule.COURIER_PUSH_NOTIFICATION_DELIVERED_EVENT,
126
+ name: CourierReactNativeModule.PushEvents.DELIVERED_EVENT,
110
127
  message: notification.userInfo
111
128
  )
112
129
 
113
130
  }
114
131
 
115
- @objc func registerPushNotificationClickedOnKilledState() {
132
+ @objc func registerPushNotificationClickedOnKilledState() -> String {
133
+
134
+ let event = CourierReactNativeModule.PushEvents.CLICKED_EVENT
116
135
 
117
136
  sendMessage(
118
- name: CourierReactNativeModule.COURIER_PUSH_NOTIFICATION_CLICKED_EVENT,
137
+ name: event,
119
138
  message: lastClickedMessage
120
139
  )
121
140
 
141
+ return event
142
+
122
143
  }
123
144
 
124
145
  @objc(getNotificationPermissionStatus: withRejecter:)
@@ -170,19 +191,42 @@ class CourierReactNativeModule: RCTEventEmitter {
170
191
 
171
192
  }
172
193
 
173
- @objc(getUserId: withRejecter:)
174
- func getUserId(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
194
+ @objc func getUserId() -> String? {
195
+ return Courier.shared.userId
196
+ }
197
+
198
+ @objc func addAuthenticationListener() -> String {
199
+
200
+ let listener = Courier.shared.addAuthenticationListener { [weak self] userId in
201
+
202
+ self?.sendEvent(
203
+ withName: CourierReactNativeModule.AuthEvents.USER_CHANGED,
204
+ body: userId
205
+ )
206
+
207
+ }
208
+
209
+ // Create an id and add the listener to the dictionary
210
+ let id = UUID().uuidString
211
+ authListeners[id] = listener
175
212
 
176
- let userId = Courier.shared.userId
177
- resolve(userId)
213
+ return id
178
214
 
179
215
  }
180
-
181
- @objc(getFcmToken: withRejecter:)
182
- func getFcmToken(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
216
+
217
+ @objc(removeAuthenticationListener:)
218
+ func removeAuthenticationListener(listenerId: NSString) -> String {
219
+
220
+ let id = listenerId as String
221
+
222
+ // Remove the listener
223
+ let listener = authListeners[id]
224
+ listener?.remove()
183
225
 
184
- let token = Courier.shared.fcmToken
185
- resolve(token)
226
+ // Remove from dictionary
227
+ authListeners.removeValue(forKey: id)
228
+
229
+ return id
186
230
 
187
231
  }
188
232
 
@@ -200,41 +244,17 @@ class CourierReactNativeModule: RCTEventEmitter {
200
244
  )
201
245
 
202
246
  }
203
-
204
- @objc(getApnsToken: withRejecter:)
205
- func getApnsToken(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
206
-
207
- let token = Courier.shared.apnsToken
208
- resolve(token)
209
-
247
+
248
+ @objc func getFcmToken() -> String? {
249
+ return Courier.shared.fcmToken
210
250
  }
211
251
 
212
- @objc(sendPush: withUserId: withTitle: withBody: withProviders: withResolver: withRejecter:)
213
- func sendPush(authKey: NSString, userId: NSString, title: NSString, body: NSString, providers: NSArray, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
214
-
215
- guard let courierProviders = providers as? [String] else {
216
- reject("No provider supported", CourierReactNativeModule.COURIER_ERROR_TAG, nil)
217
- return
218
- }
219
-
220
- // Courier.shared.sendPush(
221
- // authKey: authKey as String,
222
- // userId: userId as String,
223
- // title: title as String,
224
- // message: body as String,
225
- // providers: courierProviders,
226
- // onSuccess: { requestId in
227
- // resolve(requestId)
228
- // },
229
- // onFailure: { error in
230
- // reject(String(describing: error), CourierReactNative.COURIER_ERROR_TAG, nil)
231
- // }
232
- // )
233
-
252
+ @objc func getApnsToken() -> String? {
253
+ return Courier.shared.apnsToken
234
254
  }
235
255
 
236
256
  @objc(iOSForegroundPresentationOptions:)
237
- func iOSForegroundPresentationOptions(params: NSDictionary) {
257
+ func iOSForegroundPresentationOptions(params: NSDictionary) -> String {
238
258
 
239
259
  let rawValue = params.toPresentationOptions().rawValue
240
260
  NotificationCenter.default.post(
@@ -243,13 +263,7 @@ class CourierReactNativeModule: RCTEventEmitter {
243
263
  userInfo: ["options": rawValue]
244
264
  )
245
265
 
246
- }
247
-
248
- @objc(setDebugMode: withResolver: withRejecter:)
249
- func setDebugMode(isDebugging: Bool, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
250
-
251
- Courier.shared.isDebugging = isDebugging
252
- resolve(Courier.shared.isDebugging)
266
+ return String(describing: rawValue)
253
267
 
254
268
  }
255
269
 
@@ -297,8 +311,7 @@ class CourierReactNativeModule: RCTEventEmitter {
297
311
 
298
312
  }
299
313
 
300
- @objc(addInboxListener:)
301
- func addInboxListener(listenerId: NSString?) -> String {
314
+ @objc func addInboxListener() -> String {
302
315
 
303
316
  let listener = Courier.shared.addInboxListener(
304
317
  onInitialLoad: { [weak self] in
@@ -342,15 +355,6 @@ class CourierReactNativeModule: RCTEventEmitter {
342
355
 
343
356
  }
344
357
 
345
- @objc(refreshInbox: withRejecter:)
346
- func refreshInbox(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
347
-
348
- Courier.shared.refreshInbox {
349
- resolve(nil)
350
- }
351
-
352
- }
353
-
354
358
  @objc(removeInboxListener:)
355
359
  func removeInboxListener(listenerId: NSString) -> String {
356
360
 
@@ -366,12 +370,42 @@ class CourierReactNativeModule: RCTEventEmitter {
366
370
  return id
367
371
 
368
372
  }
373
+
374
+ @objc(refreshInbox: withRejecter:)
375
+ func refreshInbox(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
376
+
377
+ Courier.shared.refreshInbox {
378
+ resolve(nil)
379
+ }
380
+
381
+ }
382
+
383
+ @objc(fetchNextPageOfMessages: withRejecter:)
384
+ func fetchNextPageOfMessages(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
385
+
386
+ Courier.shared.fetchNextPageOfMessages(
387
+ onSuccess: { messages in
388
+ resolve(messages.map { $0.toDictionary() })
389
+ },
390
+ onFailure: { error in
391
+ reject(String(describing: error), CourierReactNativeModule.COURIER_ERROR_TAG, nil)
392
+ }
393
+ )
394
+
395
+ }
396
+
397
+ @objc(setInboxPaginationLimit:)
398
+ func setInboxPaginationLimit(limit: Double) -> String {
399
+ Courier.shared.inboxPaginationLimit = Int(limit)
400
+ return String(describing: Courier.shared.inboxPaginationLimit)
401
+ }
369
402
 
370
403
  override func supportedEvents() -> [String]! {
371
404
  return [
372
- CourierReactNativeModule.COURIER_PUSH_NOTIFICATION_CLICKED_EVENT,
373
- CourierReactNativeModule.COURIER_PUSH_NOTIFICATION_DELIVERED_EVENT,
374
- CourierReactNativeModule.COURIER_PUSH_NOTIFICATION_DEBUG_LOG_EVENT,
405
+ CourierReactNativeModule.LogEvents.DEBUG_LOG_EVENT,
406
+ CourierReactNativeModule.AuthEvents.USER_CHANGED,
407
+ CourierReactNativeModule.PushEvents.CLICKED_EVENT,
408
+ CourierReactNativeModule.PushEvents.DELIVERED_EVENT,
375
409
  CourierReactNativeModule.InboxEvents.INITIAL_LOADING,
376
410
  CourierReactNativeModule.InboxEvents.ERROR,
377
411
  CourierReactNativeModule.InboxEvents.MESSAGES_CHANGED
@@ -2,9 +2,7 @@
2
2
 
3
3
  @interface RCT_EXTERN_MODULE(CourierReactNativeViewManager, RCTViewManager)
4
4
 
5
- RCT_EXPORT_VIEW_PROPERTY(lightTheme, NSDictionary)
6
-
7
- RCT_EXPORT_VIEW_PROPERTY(darkTheme, NSDictionary)
5
+ RCT_EXPORT_VIEW_PROPERTY(theme, NSDictionary)
8
6
 
9
7
  RCT_EXPORT_VIEW_PROPERTY(onClickInboxMessageAtIndex, RCTBubblingEventBlock)
10
8
 
@@ -15,13 +15,7 @@ class CourierReactNativeViewManager: RCTViewManager {
15
15
 
16
16
  class CourierReactNativeView : UIView {
17
17
 
18
- @objc var lightTheme: NSDictionary? = [:] {
19
- didSet {
20
- refreshInbox()
21
- }
22
- }
23
-
24
- @objc var darkTheme: NSDictionary? = [:] {
18
+ @objc var theme: NSDictionary? = [:] {
25
19
  didSet {
26
20
  refreshInbox()
27
21
  }
@@ -33,19 +27,18 @@ class CourierReactNativeView : UIView {
33
27
 
34
28
  @objc var onScrollInbox: RCTBubblingEventBlock? = nil
35
29
 
36
- override init(frame: CGRect) {
37
- super.init(frame: frame)
38
- refreshInbox()
39
- }
40
-
41
- required init?(coder: NSCoder) {
42
- super.init(coder: coder)
43
- refreshInbox()
44
- }
45
-
46
30
  private func refreshInbox() {
47
31
 
48
- subviews.forEach { $0.removeFromSuperview() }
32
+ // Disable animations
33
+ UIView.setAnimationsEnabled(false)
34
+
35
+ // Remove all previous views
36
+ subviews.forEach {
37
+ $0.removeFromSuperview()
38
+ }
39
+
40
+ let lightTheme = theme?["light"] as? NSDictionary
41
+ let darkTheme = theme?["dark"] as? NSDictionary
49
42
 
50
43
  // Create the view
51
44
  let courierInbox = CourierInbox(
@@ -86,6 +79,9 @@ class CourierReactNativeView : UIView {
86
79
  courierInbox.trailingAnchor.constraint(equalTo: trailingAnchor),
87
80
  ])
88
81
 
82
+ // Enable animations
83
+ UIView.setAnimationsEnabled(true)
84
+
89
85
  }
90
86
 
91
87
  func dictionaryToTheme(dictionary: NSDictionary?) -> CourierInboxTheme? {