@trycourier/courier-react-native 2.0.2 → 2.1.0
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.
- package/README.md +37 -8
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/courierreactnative/CourierReactNativeModule.kt +50 -0
- package/android/src/main/java/com/courierreactnative/Extensions.kt +51 -3
- package/courier-react-native.podspec +1 -1
- package/ios/CourierReactNative.xcodeproj/project.xcworkspace/contents.xcworkspacedata +3 -0
- package/ios/CourierReactNative.xcodeproj/project.xcworkspace/xcuserdata/mike.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/CourierReactNativeModule.m +27 -0
- package/ios/CourierReactNativeModule.swift +51 -15
- package/ios/CourierReactNativeViewManager.swift +0 -123
- package/ios/Utils.swift +199 -0
- package/lib/commonjs/hooks/CourierProvider.js +8 -12
- package/lib/commonjs/hooks/CourierProvider.js.map +1 -1
- package/lib/commonjs/index.js +35 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/CourierPaging.js +2 -0
- package/lib/commonjs/models/CourierPaging.js.map +1 -0
- package/lib/commonjs/models/CourierUserPreferences.js +6 -0
- package/lib/commonjs/models/CourierUserPreferences.js.map +1 -0
- package/lib/commonjs/models/CourierUserPreferencesChannel.js +17 -0
- package/lib/commonjs/models/CourierUserPreferencesChannel.js.map +1 -0
- package/lib/commonjs/models/CourierUserPreferencesStatus.js +15 -0
- package/lib/commonjs/models/CourierUserPreferencesStatus.js.map +1 -0
- package/lib/commonjs/models/CourierUserPreferencesTopic.js +6 -0
- package/lib/commonjs/models/CourierUserPreferencesTopic.js.map +1 -0
- package/lib/module/hooks/CourierProvider.js +8 -12
- package/lib/module/hooks/CourierProvider.js.map +1 -1
- package/lib/module/index.js +23 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/CourierPaging.js +2 -0
- package/lib/module/models/CourierPaging.js.map +1 -0
- package/lib/module/models/CourierUserPreferences.js +2 -0
- package/lib/module/models/CourierUserPreferences.js.map +1 -0
- package/lib/module/models/CourierUserPreferencesChannel.js +10 -0
- package/lib/module/models/CourierUserPreferencesChannel.js.map +1 -0
- package/lib/module/models/CourierUserPreferencesStatus.js +8 -0
- package/lib/module/models/CourierUserPreferencesStatus.js.map +1 -0
- package/lib/module/models/CourierUserPreferencesTopic.js +2 -0
- package/lib/module/models/CourierUserPreferencesTopic.js.map +1 -0
- package/lib/typescript/index.d.ts +27 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/models/CourierPaging.d.ts +5 -0
- package/lib/typescript/models/CourierPaging.d.ts.map +1 -0
- package/lib/typescript/models/CourierUserPreferences.d.ts +7 -0
- package/lib/typescript/models/CourierUserPreferences.d.ts.map +1 -0
- package/lib/typescript/models/CourierUserPreferencesChannel.d.ts +9 -0
- package/lib/typescript/models/CourierUserPreferencesChannel.d.ts.map +1 -0
- package/lib/typescript/models/CourierUserPreferencesStatus.d.ts +7 -0
- package/lib/typescript/models/CourierUserPreferencesStatus.d.ts.map +1 -0
- package/lib/typescript/models/CourierUserPreferencesTopic.d.ts +11 -0
- package/lib/typescript/models/CourierUserPreferencesTopic.d.ts.map +1 -0
- package/lib/typescript/views/CourierInboxView.d.ts +3 -3
- package/lib/typescript/views/CourierInboxView.d.ts.map +1 -1
- package/package.json +4 -2
- package/src/hooks/CourierProvider.tsx +9 -9
- package/src/index.tsx +27 -0
- package/src/models/CourierPaging.tsx +4 -0
- package/src/models/CourierUserPreferences.tsx +7 -0
- package/src/models/CourierUserPreferencesChannel.tsx +8 -0
- package/src/models/CourierUserPreferencesStatus.tsx +6 -0
- package/src/models/CourierUserPreferencesTopic.tsx +11 -0
- package/src/views/CourierInboxView.tsx +3 -3
package/README.md
CHANGED
|
@@ -96,10 +96,10 @@ buildscript {
|
|
|
96
96
|
ext {
|
|
97
97
|
|
|
98
98
|
// Double check these values
|
|
99
|
-
buildToolsVersion = "
|
|
99
|
+
buildToolsVersion = "33.0.0"
|
|
100
100
|
minSdkVersion = 23
|
|
101
|
-
compileSdkVersion =
|
|
102
|
-
targetSdkVersion =
|
|
101
|
+
compileSdkVersion = 33
|
|
102
|
+
targetSdkVersion = 33
|
|
103
103
|
..
|
|
104
104
|
}
|
|
105
105
|
|
|
@@ -118,6 +118,22 @@ buildscript {
|
|
|
118
118
|
|
|
119
119
|
 
|
|
120
120
|
|
|
121
|
+
### 3. Extend the `CourierReactNativeActivity`
|
|
122
|
+
|
|
123
|
+
In your Android project, change your `MainActivity` to extend the `CourierReactNativeActivity`.
|
|
124
|
+
|
|
125
|
+
This allows the Courier SDK to manage the current user between app sessions.
|
|
126
|
+
|
|
127
|
+
```java
|
|
128
|
+
import com.courierreactnative.CourierReactNativeActivity;
|
|
129
|
+
|
|
130
|
+
public class MainActivity extends CourierReactNativeActivity {
|
|
131
|
+
..
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
 
|
|
136
|
+
|
|
121
137
|
# Getting Started
|
|
122
138
|
|
|
123
139
|
These are all the available features of the SDK.
|
|
@@ -136,12 +152,12 @@ These are all the available features of the SDK.
|
|
|
136
152
|
1
|
|
137
153
|
</td>
|
|
138
154
|
<td align="left">
|
|
139
|
-
<a href="https://github.com/trycourier/courier-react-native/blob/
|
|
155
|
+
<a href="https://github.com/trycourier/courier-react-native/blob/master/Docs/Authentication.md">
|
|
140
156
|
<code>Authentication</code>
|
|
141
157
|
</a>
|
|
142
158
|
</td>
|
|
143
159
|
<td align="left">
|
|
144
|
-
Manages user credentials between app sessions. Required if you would like to use <a href="https://github.com/trycourier/courier-react-native/blob/
|
|
160
|
+
Manages user credentials between app sessions. Required if you would like to use <a href="https://github.com/trycourier/courier-react-native/blob/master/Docs/Inbox.md"><code>Courier Inbox</code></a> and <a href="https://github.com/trycourier/courier-react-native/blob/master/Docs/PushNotifications.md"><code>Push Notifications</code></a>.
|
|
145
161
|
</td>
|
|
146
162
|
</tr>
|
|
147
163
|
<tr width="600px">
|
|
@@ -149,7 +165,7 @@ These are all the available features of the SDK.
|
|
|
149
165
|
2
|
|
150
166
|
</td>
|
|
151
167
|
<td align="left">
|
|
152
|
-
<a href="https://github.com/trycourier/courier-react-native/blob/
|
|
168
|
+
<a href="https://github.com/trycourier/courier-react-native/blob/master/Docs/Inbox.md">
|
|
153
169
|
<code>Courier Inbox</code>
|
|
154
170
|
</a>
|
|
155
171
|
</td>
|
|
@@ -162,7 +178,7 @@ These are all the available features of the SDK.
|
|
|
162
178
|
3
|
|
163
179
|
</td>
|
|
164
180
|
<td align="left">
|
|
165
|
-
<a href="https://github.com/trycourier/courier-react-native/blob/
|
|
181
|
+
<a href="https://github.com/trycourier/courier-react-native/blob/master/Docs/PushNotifications.md">
|
|
166
182
|
<code>Push Notifications</code>
|
|
167
183
|
</a>
|
|
168
184
|
</td>
|
|
@@ -170,6 +186,19 @@ These are all the available features of the SDK.
|
|
|
170
186
|
Automatically manages push notification device tokens and gives convenient functions for handling push notification receiving and clicking.
|
|
171
187
|
</td>
|
|
172
188
|
</tr>
|
|
189
|
+
<tr width="600px">
|
|
190
|
+
<td align="center">
|
|
191
|
+
4
|
|
192
|
+
</td>
|
|
193
|
+
<td align="left">
|
|
194
|
+
<a href="https://github.com/trycourier/courier-react-native/blob/master/Docs/Preferences.md">
|
|
195
|
+
<code>Preferences</code>
|
|
196
|
+
</a>
|
|
197
|
+
</td>
|
|
198
|
+
<td align="left">
|
|
199
|
+
Allow users to update which types of notifications they would like to receive.
|
|
200
|
+
</td>
|
|
201
|
+
</tr>
|
|
173
202
|
</tbody>
|
|
174
203
|
</table>
|
|
175
204
|
|
|
@@ -188,7 +217,7 @@ Starter projects using this SDK.
|
|
|
188
217
|
<tbody>
|
|
189
218
|
<tr width="1000px">
|
|
190
219
|
<td align="left">
|
|
191
|
-
<a href="https://github.com/trycourier/courier-react-native/tree/
|
|
220
|
+
<a href="https://github.com/trycourier/courier-react-native/tree/master/example">
|
|
192
221
|
<code>Example</code>
|
|
193
222
|
</a>
|
|
194
223
|
</td>
|
package/android/build.gradle
CHANGED
|
@@ -101,7 +101,7 @@ dependencies {
|
|
|
101
101
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
102
102
|
|
|
103
103
|
// Courier Core SDK
|
|
104
|
-
api 'com.github.trycourier:courier-android:2.
|
|
104
|
+
api 'com.github.trycourier:courier-android:2.1.1'
|
|
105
105
|
api 'androidx.recyclerview:recyclerview:1.3.1'
|
|
106
106
|
|
|
107
107
|
}
|
|
@@ -274,4 +274,54 @@ class CourierReactNativeModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
274
274
|
return Courier.shared.inboxPaginationLimit.toString()
|
|
275
275
|
}
|
|
276
276
|
|
|
277
|
+
@ReactMethod
|
|
278
|
+
fun getUserPreferences(paginationCursor: String, promise: Promise) {
|
|
279
|
+
|
|
280
|
+
val cursor = if (paginationCursor != "") paginationCursor else null
|
|
281
|
+
|
|
282
|
+
Courier.shared.getUserPreferences(
|
|
283
|
+
paginationCursor = cursor,
|
|
284
|
+
onSuccess = { preferences ->
|
|
285
|
+
promise.resolve(preferences.toWritableMap())
|
|
286
|
+
},
|
|
287
|
+
onFailure = { e ->
|
|
288
|
+
promise.reject(CourierEvents.COURIER_ERROR_TAG, e)
|
|
289
|
+
}
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
@ReactMethod
|
|
295
|
+
fun getUserPreferencesTopic(topicId: String, promise: Promise) {
|
|
296
|
+
Courier.shared.getUserPreferenceTopic(
|
|
297
|
+
topicId = topicId,
|
|
298
|
+
onSuccess = { topic ->
|
|
299
|
+
promise.resolve(topic.toWritableMap())
|
|
300
|
+
},
|
|
301
|
+
onFailure = { e ->
|
|
302
|
+
promise.reject(CourierEvents.COURIER_ERROR_TAG, e)
|
|
303
|
+
}
|
|
304
|
+
)
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
@ReactMethod
|
|
308
|
+
fun putUserPreferencesTopic(topicId: String, status: String, hasCustomRouting: Boolean, customRouting: ReadableArray, promise: Promise) {
|
|
309
|
+
|
|
310
|
+
val routing = customRouting.toArrayList().map { CourierPreferenceChannel.fromString(it as String) }
|
|
311
|
+
|
|
312
|
+
Courier.shared.putUserPreferenceTopic(
|
|
313
|
+
topicId = topicId,
|
|
314
|
+
status = CourierPreferenceStatus.fromString(status),
|
|
315
|
+
hasCustomRouting = hasCustomRouting,
|
|
316
|
+
customRouting = routing,
|
|
317
|
+
onSuccess = {
|
|
318
|
+
promise.resolve(null)
|
|
319
|
+
},
|
|
320
|
+
onFailure = { e ->
|
|
321
|
+
promise.reject(CourierEvents.COURIER_ERROR_TAG, e)
|
|
322
|
+
}
|
|
323
|
+
)
|
|
324
|
+
|
|
325
|
+
}
|
|
326
|
+
|
|
277
327
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
package com.courierreactnative
|
|
2
2
|
|
|
3
|
-
import com.courier.android.models
|
|
4
|
-
import com.courier.android.models.InboxMessage
|
|
3
|
+
import com.courier.android.models.*
|
|
5
4
|
import com.facebook.react.bridge.Arguments
|
|
6
5
|
import com.facebook.react.bridge.ReactContext
|
|
7
6
|
import com.facebook.react.bridge.WritableArray
|
|
@@ -12,9 +11,58 @@ internal fun ReactContext.sendEvent(eventName: String, value: Any?) {
|
|
|
12
11
|
getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java).emit(eventName, value)
|
|
13
12
|
}
|
|
14
13
|
|
|
14
|
+
internal fun CourierUserPreferences.toWritableMap(): WritableMap {
|
|
15
|
+
|
|
16
|
+
val map = Arguments.createMap()
|
|
17
|
+
|
|
18
|
+
val itemsArray = Arguments.createArray()
|
|
19
|
+
items.forEach { topic ->
|
|
20
|
+
itemsArray.pushMap(topic.toWritableMap())
|
|
21
|
+
}
|
|
22
|
+
map.putArray("items", itemsArray)
|
|
23
|
+
|
|
24
|
+
map.putMap("paging", paging.toWritableMap())
|
|
25
|
+
|
|
26
|
+
return map
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
internal fun CourierPreferenceTopic.toWritableMap(): WritableMap {
|
|
31
|
+
|
|
32
|
+
val map = Arguments.createMap()
|
|
33
|
+
map.putString("defaultStatus", defaultStatus.value)
|
|
34
|
+
map.putBoolean("hasCustomRouting", hasCustomRouting)
|
|
35
|
+
map.putString("status", status.value)
|
|
36
|
+
map.putString("topicId", topicId)
|
|
37
|
+
map.putString("topicName", topicName)
|
|
38
|
+
|
|
39
|
+
val actionsArray = Arguments.createArray()
|
|
40
|
+
customRouting.forEach { routing ->
|
|
41
|
+
actionsArray.pushString(routing.value)
|
|
42
|
+
}
|
|
43
|
+
map.putArray("customRouting", actionsArray)
|
|
44
|
+
|
|
45
|
+
return map
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
internal fun Paging.toWritableMap(): WritableMap {
|
|
50
|
+
|
|
51
|
+
val map = Arguments.createMap()
|
|
52
|
+
|
|
53
|
+
cursor?.let {
|
|
54
|
+
map.putString("cursor", it)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
map.putBoolean("more", more)
|
|
58
|
+
|
|
59
|
+
return map
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
15
63
|
@JvmName("toWritableArrayInboxMessage")
|
|
16
64
|
internal fun List<InboxMessage>.toWritableArray(): WritableArray {
|
|
17
|
-
|
|
65
|
+
|
|
18
66
|
val messagesArray = Arguments.createArray()
|
|
19
67
|
|
|
20
68
|
forEach { message ->
|
|
@@ -17,7 +17,7 @@ Pod::Spec.new do |s|
|
|
|
17
17
|
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
18
18
|
|
|
19
19
|
# Courier Core Dependency
|
|
20
|
-
s.dependency "Courier_iOS", "2.
|
|
20
|
+
s.dependency "Courier_iOS", "2.1.3"
|
|
21
21
|
|
|
22
22
|
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
|
|
23
23
|
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
|
|
Binary file
|
|
@@ -95,6 +95,33 @@ RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
|
|
|
95
95
|
setInboxPaginationLimit: (double)limit
|
|
96
96
|
)
|
|
97
97
|
|
|
98
|
+
RCT_EXTERN_METHOD(
|
|
99
|
+
getUserPreferences: (NSString*)paginationCursor
|
|
100
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
101
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
RCT_EXTERN_METHOD(
|
|
105
|
+
getUserPreferencesTopic: (NSString*)topicId
|
|
106
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
107
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
RCT_EXTERN_METHOD(
|
|
111
|
+
getUserPreferencesTopic: (NSString*)topicId
|
|
112
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
113
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
RCT_EXTERN_METHOD(
|
|
117
|
+
putUserPreferencesTopic: (NSString*)topicId
|
|
118
|
+
withStatus: (NSString*)status
|
|
119
|
+
withHasCustomRouting: (BOOL*)hasCustomRouting
|
|
120
|
+
withCustomRouting: (NSArray*)customRouting
|
|
121
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
122
|
+
withRejecter: (RCTPromiseRejectBlock)reject
|
|
123
|
+
)
|
|
124
|
+
|
|
98
125
|
RCT_EXTERN_METHOD(
|
|
99
126
|
registerPushNotificationClickedOnKilledState
|
|
100
127
|
)
|
|
@@ -380,6 +380,57 @@ class CourierReactNativeModule: RCTEventEmitter {
|
|
|
380
380
|
Courier.shared.inboxPaginationLimit = Int(limit)
|
|
381
381
|
return String(describing: Courier.shared.inboxPaginationLimit)
|
|
382
382
|
}
|
|
383
|
+
|
|
384
|
+
@objc(getUserPreferences: withResolver: withRejecter:)
|
|
385
|
+
func getUserPreferences(paginationCursor: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
386
|
+
|
|
387
|
+
let cursor = paginationCursor != "" ? paginationCursor as String : nil
|
|
388
|
+
|
|
389
|
+
Courier.shared.getUserPreferences(
|
|
390
|
+
paginationCursor: cursor,
|
|
391
|
+
onSuccess: { preferences in
|
|
392
|
+
resolve(preferences.toDictionary())
|
|
393
|
+
},
|
|
394
|
+
onFailure: { error in
|
|
395
|
+
reject(String(describing: error), CourierReactNativeModule.COURIER_ERROR_TAG, nil)
|
|
396
|
+
}
|
|
397
|
+
)
|
|
398
|
+
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
@objc(getUserPreferencesTopic: withResolver: withRejecter:)
|
|
402
|
+
func getUserPreferencesTopic(topicId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
403
|
+
|
|
404
|
+
Courier.shared.getUserPreferencesTopic(
|
|
405
|
+
topicId: topicId as String,
|
|
406
|
+
onSuccess: { topic in
|
|
407
|
+
resolve(topic.toDictionary())
|
|
408
|
+
},
|
|
409
|
+
onFailure: { error in
|
|
410
|
+
reject(String(describing: error), CourierReactNativeModule.COURIER_ERROR_TAG, nil)
|
|
411
|
+
}
|
|
412
|
+
)
|
|
413
|
+
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
@objc(putUserPreferencesTopic: withStatus: withHasCustomRouting: withCustomRouting: withResolver: withRejecter:)
|
|
417
|
+
func putUserPreferencesTopic(topicId: NSString, status: NSString, hasCustomRouting: Bool, customRouting: [NSString], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
Courier.shared.putUserPreferencesTopic(
|
|
421
|
+
topicId: topicId as String,
|
|
422
|
+
status: CourierUserPreferencesStatus(rawValue: status as String) ?? .unknown,
|
|
423
|
+
hasCustomRouting: hasCustomRouting,
|
|
424
|
+
customRouting: customRouting.map { CourierUserPreferencesChannel(rawValue: $0 as String) ?? .unknown },
|
|
425
|
+
onSuccess: {
|
|
426
|
+
resolve(nil)
|
|
427
|
+
},
|
|
428
|
+
onFailure: { error in
|
|
429
|
+
reject(String(describing: error), CourierReactNativeModule.COURIER_ERROR_TAG, nil)
|
|
430
|
+
}
|
|
431
|
+
)
|
|
432
|
+
|
|
433
|
+
}
|
|
383
434
|
|
|
384
435
|
override func supportedEvents() -> [String]! {
|
|
385
436
|
return [
|
|
@@ -432,18 +483,3 @@ extension NSDictionary {
|
|
|
432
483
|
}
|
|
433
484
|
|
|
434
485
|
}
|
|
435
|
-
|
|
436
|
-
extension UNAuthorizationStatus {
|
|
437
|
-
|
|
438
|
-
var name: String {
|
|
439
|
-
switch (self) {
|
|
440
|
-
case .notDetermined: return "notDetermined"
|
|
441
|
-
case .denied: return "denied"
|
|
442
|
-
case .authorized: return "authorized"
|
|
443
|
-
case .provisional: return "provisional"
|
|
444
|
-
case .ephemeral: return "ephemeral"
|
|
445
|
-
@unknown default: return "unknown"
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
}
|
|
@@ -219,126 +219,3 @@ class CourierReactNativeView : UIView {
|
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
}
|
|
222
|
-
|
|
223
|
-
internal extension InboxMessage {
|
|
224
|
-
|
|
225
|
-
@objc func toDictionary() -> NSDictionary {
|
|
226
|
-
|
|
227
|
-
let dictionary: [String: Any?] = [
|
|
228
|
-
"messageId": messageId,
|
|
229
|
-
"title": title,
|
|
230
|
-
"body": body,
|
|
231
|
-
"preview": preview,
|
|
232
|
-
"created": created,
|
|
233
|
-
"actions": actions?.map { $0.toDictionary() },
|
|
234
|
-
"data": data,
|
|
235
|
-
"read": isRead,
|
|
236
|
-
"opened": isOpened,
|
|
237
|
-
"archived": isArchived
|
|
238
|
-
]
|
|
239
|
-
|
|
240
|
-
let mutableDictionary = NSMutableDictionary()
|
|
241
|
-
for (key, value) in dictionary {
|
|
242
|
-
if let unwrappedValue = value {
|
|
243
|
-
mutableDictionary[key] = unwrappedValue
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
return mutableDictionary
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
internal extension InboxAction {
|
|
254
|
-
|
|
255
|
-
@objc func toDictionary() -> NSDictionary {
|
|
256
|
-
|
|
257
|
-
let dictionary: [String: Any?] = [
|
|
258
|
-
"content": content,
|
|
259
|
-
"href": href,
|
|
260
|
-
"data": data
|
|
261
|
-
]
|
|
262
|
-
|
|
263
|
-
let mutableDictionary = NSMutableDictionary()
|
|
264
|
-
for (key, value) in dictionary {
|
|
265
|
-
if let unwrappedValue = value {
|
|
266
|
-
mutableDictionary[key] = unwrappedValue
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
return mutableDictionary
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
internal extension String {
|
|
277
|
-
|
|
278
|
-
func toRowAnimation() -> UITableView.RowAnimation {
|
|
279
|
-
|
|
280
|
-
switch self.lowercased() {
|
|
281
|
-
case "fade": return .fade
|
|
282
|
-
case "right": return .right
|
|
283
|
-
case "left": return .left
|
|
284
|
-
case "top": return .top
|
|
285
|
-
case "bottom": return .bottom
|
|
286
|
-
case "none": return .none
|
|
287
|
-
case "middle": return .middle
|
|
288
|
-
case "automatic":
|
|
289
|
-
if #available(iOS 11.0, *) {
|
|
290
|
-
return .automatic
|
|
291
|
-
} else {
|
|
292
|
-
return .fade
|
|
293
|
-
}
|
|
294
|
-
default: return .fade
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
func toSeparatorStyle() -> UITableViewCell.SeparatorStyle {
|
|
300
|
-
|
|
301
|
-
switch self.lowercased() {
|
|
302
|
-
case "none": return .none
|
|
303
|
-
case "singleLine": return .singleLine
|
|
304
|
-
case "singleLineEtched": return .singleLineEtched
|
|
305
|
-
default: return .singleLine
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
func toSelectionStyle() -> UITableViewCell.SelectionStyle? {
|
|
311
|
-
|
|
312
|
-
switch self.lowercased() {
|
|
313
|
-
case "none": return .none
|
|
314
|
-
case "blue": return .blue
|
|
315
|
-
case "gray": return .gray
|
|
316
|
-
case "default": return .default
|
|
317
|
-
default: return .default
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
func toColor() -> UIColor? {
|
|
323
|
-
|
|
324
|
-
var hexSanitized = trimmingCharacters(in: .whitespacesAndNewlines)
|
|
325
|
-
hexSanitized = hexSanitized.replacingOccurrences(of: "#", with: "")
|
|
326
|
-
|
|
327
|
-
var rgb: UInt64 = 0
|
|
328
|
-
|
|
329
|
-
Scanner(string: hexSanitized).scanHexInt64(&rgb)
|
|
330
|
-
|
|
331
|
-
guard hexSanitized.count == 6 else {
|
|
332
|
-
return nil
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
return UIColor(
|
|
336
|
-
red: CGFloat((rgb & 0xFF0000) >> 16) / 255.0,
|
|
337
|
-
green: CGFloat((rgb & 0x00FF00) >> 8) / 255.0,
|
|
338
|
-
blue: CGFloat(rgb & 0x0000FF) / 255.0,
|
|
339
|
-
alpha: 1.0
|
|
340
|
-
)
|
|
341
|
-
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
}
|
package/ios/Utils.swift
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Utils.swift
|
|
3
|
+
// courier-react-native
|
|
4
|
+
//
|
|
5
|
+
// Created by Michael Miller on 10/23/23.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import Courier_iOS
|
|
10
|
+
|
|
11
|
+
extension UNAuthorizationStatus {
|
|
12
|
+
|
|
13
|
+
var name: String {
|
|
14
|
+
switch (self) {
|
|
15
|
+
case .notDetermined: return "notDetermined"
|
|
16
|
+
case .denied: return "denied"
|
|
17
|
+
case .authorized: return "authorized"
|
|
18
|
+
case .provisional: return "provisional"
|
|
19
|
+
case .ephemeral: return "ephemeral"
|
|
20
|
+
@unknown default: return "unknown"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
internal extension [String: Any?] {
|
|
27
|
+
|
|
28
|
+
func clean() -> NSMutableDictionary {
|
|
29
|
+
|
|
30
|
+
let mutableDictionary = NSMutableDictionary()
|
|
31
|
+
for (key, value) in self {
|
|
32
|
+
if let unwrappedValue = value {
|
|
33
|
+
mutableDictionary[key] = unwrappedValue
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return mutableDictionary
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
internal extension CourierUserPreferences {
|
|
44
|
+
|
|
45
|
+
@objc func toDictionary() -> NSDictionary {
|
|
46
|
+
|
|
47
|
+
let dictionary: [String: Any?] = [
|
|
48
|
+
"items": items.map { $0.toDictionary() },
|
|
49
|
+
"paging": paging.toDictionary(),
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
return dictionary.clean()
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
internal extension CourierUserPreferencesTopic {
|
|
59
|
+
|
|
60
|
+
@objc func toDictionary() -> NSDictionary {
|
|
61
|
+
|
|
62
|
+
let dictionary: [String: Any?] = [
|
|
63
|
+
"defaultStatus": defaultStatus.rawValue,
|
|
64
|
+
"hasCustomRouting": hasCustomRouting,
|
|
65
|
+
"customRouting": customRouting.map { $0.rawValue },
|
|
66
|
+
"status": status,
|
|
67
|
+
"topicId": topicId,
|
|
68
|
+
"topicName": topicName,
|
|
69
|
+
]
|
|
70
|
+
|
|
71
|
+
return dictionary.clean()
|
|
72
|
+
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
internal extension CourierUserPreferencesPaging {
|
|
78
|
+
|
|
79
|
+
@objc func toDictionary() -> NSDictionary {
|
|
80
|
+
|
|
81
|
+
let dictionary: [String: Any?] = [
|
|
82
|
+
"cursor": cursor,
|
|
83
|
+
"more": more,
|
|
84
|
+
]
|
|
85
|
+
|
|
86
|
+
return dictionary.clean()
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
internal extension InboxMessage {
|
|
93
|
+
|
|
94
|
+
@objc func toDictionary() -> NSDictionary {
|
|
95
|
+
|
|
96
|
+
let dictionary: [String: Any?] = [
|
|
97
|
+
"messageId": messageId,
|
|
98
|
+
"title": title,
|
|
99
|
+
"body": body,
|
|
100
|
+
"preview": preview,
|
|
101
|
+
"created": created,
|
|
102
|
+
"actions": actions?.map { $0.toDictionary() },
|
|
103
|
+
"data": data,
|
|
104
|
+
"read": isRead,
|
|
105
|
+
"opened": isOpened,
|
|
106
|
+
"archived": isArchived
|
|
107
|
+
]
|
|
108
|
+
|
|
109
|
+
return dictionary.clean()
|
|
110
|
+
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
internal extension InboxAction {
|
|
116
|
+
|
|
117
|
+
@objc func toDictionary() -> NSDictionary {
|
|
118
|
+
|
|
119
|
+
let dictionary: [String: Any?] = [
|
|
120
|
+
"content": content,
|
|
121
|
+
"href": href,
|
|
122
|
+
"data": data
|
|
123
|
+
]
|
|
124
|
+
|
|
125
|
+
return dictionary.clean()
|
|
126
|
+
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
internal extension String {
|
|
132
|
+
|
|
133
|
+
func toRowAnimation() -> UITableView.RowAnimation {
|
|
134
|
+
|
|
135
|
+
switch self.lowercased() {
|
|
136
|
+
case "fade": return .fade
|
|
137
|
+
case "right": return .right
|
|
138
|
+
case "left": return .left
|
|
139
|
+
case "top": return .top
|
|
140
|
+
case "bottom": return .bottom
|
|
141
|
+
case "none": return .none
|
|
142
|
+
case "middle": return .middle
|
|
143
|
+
case "automatic":
|
|
144
|
+
if #available(iOS 11.0, *) {
|
|
145
|
+
return .automatic
|
|
146
|
+
} else {
|
|
147
|
+
return .fade
|
|
148
|
+
}
|
|
149
|
+
default: return .fade
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
func toSeparatorStyle() -> UITableViewCell.SeparatorStyle {
|
|
155
|
+
|
|
156
|
+
switch self.lowercased() {
|
|
157
|
+
case "none": return .none
|
|
158
|
+
case "singleLine": return .singleLine
|
|
159
|
+
case "singleLineEtched": return .singleLineEtched
|
|
160
|
+
default: return .singleLine
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
func toSelectionStyle() -> UITableViewCell.SelectionStyle? {
|
|
166
|
+
|
|
167
|
+
switch self.lowercased() {
|
|
168
|
+
case "none": return .none
|
|
169
|
+
case "blue": return .blue
|
|
170
|
+
case "gray": return .gray
|
|
171
|
+
case "default": return .default
|
|
172
|
+
default: return .default
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
func toColor() -> UIColor? {
|
|
178
|
+
|
|
179
|
+
var hexSanitized = trimmingCharacters(in: .whitespacesAndNewlines)
|
|
180
|
+
hexSanitized = hexSanitized.replacingOccurrences(of: "#", with: "")
|
|
181
|
+
|
|
182
|
+
var rgb: UInt64 = 0
|
|
183
|
+
|
|
184
|
+
Scanner(string: hexSanitized).scanHexInt64(&rgb)
|
|
185
|
+
|
|
186
|
+
guard hexSanitized.count == 6 else {
|
|
187
|
+
return nil
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return UIColor(
|
|
191
|
+
red: CGFloat((rgb & 0xFF0000) >> 16) / 255.0,
|
|
192
|
+
green: CGFloat((rgb & 0x00FF00) >> 8) / 255.0,
|
|
193
|
+
blue: CGFloat(rgb & 0x0000FF) / 255.0,
|
|
194
|
+
alpha: 1.0
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
}
|