@trycourier/courier-react-native 4.1.0 → 5.0.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/android/build.gradle +1 -1
- package/android/src/main/java/com/courierreactnative/CourierInboxViewManager.kt +131 -2
- package/android/src/main/java/com/courierreactnative/CourierReactNativeActivity.kt +6 -4
- package/android/src/main/java/com/courierreactnative/CourierSharedModule.kt +71 -20
- package/android/src/main/java/com/courierreactnative/ReactNativeModule.kt +1 -2
- package/android/src/main/java/com/courierreactnative/Utils.kt +37 -144
- package/courier-react-native.podspec +1 -1
- package/ios/CourierInboxReactNativeManager.m +2 -0
- package/ios/CourierInboxReactNativeManager.swift +165 -0
- package/ios/CourierReactNativeDelegate.m +1 -1
- package/ios/CourierReactNativeEventEmitter.swift +1 -1
- package/ios/CourierReactNativeModule.m +9 -2
- package/ios/CourierSharedModule.swift +121 -50
- package/ios/Utils.swift +1 -2
- package/lib/commonjs/Modules.js +5 -0
- package/lib/commonjs/Modules.js.map +1 -1
- package/lib/commonjs/index.js +84 -22
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/CourierInboxListener.js.map +1 -1
- package/lib/commonjs/models/InboxMessageFeed.js +2 -0
- package/lib/commonjs/models/InboxMessageFeed.js.map +1 -0
- package/lib/commonjs/views/CourierInboxView.js +3 -8
- package/lib/commonjs/views/CourierInboxView.js.map +1 -1
- package/lib/commonjs/views/CourierPreferencesView.js +2 -8
- package/lib/commonjs/views/CourierPreferencesView.js.map +1 -1
- package/lib/module/Modules.js +6 -1
- package/lib/module/Modules.js.map +1 -1
- package/lib/module/index.js +84 -22
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/CourierInboxListener.js.map +1 -1
- package/lib/module/models/InboxMessageFeed.js +2 -0
- package/lib/module/models/InboxMessageFeed.js.map +1 -0
- package/lib/module/views/CourierInboxView.js +4 -9
- package/lib/module/views/CourierInboxView.js.map +1 -1
- package/lib/module/views/CourierPreferencesView.js +3 -9
- package/lib/module/views/CourierPreferencesView.js.map +1 -1
- package/lib/typescript/src/Modules.d.ts +1 -0
- package/lib/typescript/src/Modules.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +20 -3
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/models/CourierInboxListener.d.ts +7 -0
- package/lib/typescript/src/models/CourierInboxListener.d.ts.map +1 -1
- package/lib/typescript/src/models/CourierInboxTheme.d.ts +27 -0
- package/lib/typescript/src/models/CourierInboxTheme.d.ts.map +1 -1
- package/lib/typescript/src/models/InboxMessageFeed.d.ts +2 -0
- package/lib/typescript/src/models/InboxMessageFeed.d.ts.map +1 -0
- package/lib/typescript/src/views/CourierInboxView.d.ts +1 -0
- package/lib/typescript/src/views/CourierInboxView.d.ts.map +1 -1
- package/lib/typescript/src/views/CourierPreferencesView.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Modules.tsx +9 -1
- package/src/index.tsx +100 -27
- package/src/models/CourierInboxListener.tsx +8 -1
- package/src/models/CourierInboxTheme.tsx +33 -0
- package/src/models/InboxMessageFeed.tsx +1 -0
- package/src/views/CourierInboxView.tsx +5 -15
- package/src/views/CourierPreferencesView.tsx +3 -15
package/android/build.gradle
CHANGED
|
@@ -104,7 +104,7 @@ dependencies {
|
|
|
104
104
|
implementation 'com.google.code.gson:gson:2.11.0'
|
|
105
105
|
|
|
106
106
|
// Courier Core SDK
|
|
107
|
-
api 'com.github.trycourier:courier-android:4.
|
|
107
|
+
api 'com.github.trycourier:courier-android:4.6.3'
|
|
108
108
|
api 'androidx.recyclerview:recyclerview:1.3.2'
|
|
109
109
|
|
|
110
110
|
}
|
|
@@ -63,7 +63,7 @@ class CourierInboxViewManager : SimpleViewManager<CourierInbox>() {
|
|
|
63
63
|
|
|
64
64
|
view.setOnClickActionListener { action, message, index ->
|
|
65
65
|
val map = Arguments.createMap()
|
|
66
|
-
map.
|
|
66
|
+
map.putString("action", action.toJson())
|
|
67
67
|
map.putString("message", message.toJson())
|
|
68
68
|
map.putInt("index", index)
|
|
69
69
|
themedReactContext?.sendEvent(ON_CLICK_ACTION_AT_INDEX, map)
|
|
@@ -102,6 +102,12 @@ class CourierInboxViewManager : SimpleViewManager<CourierInbox>() {
|
|
|
102
102
|
|
|
103
103
|
val brandId = getString("brandId")
|
|
104
104
|
|
|
105
|
+
val tabIndicatorColor = getString("tabIndicatorColor")
|
|
106
|
+
val tabStyle = getMap("tabStyle")
|
|
107
|
+
|
|
108
|
+
val readingSwipeActionStyle = getMap("readingSwipeActionStyle")
|
|
109
|
+
val archivingSwipeActionStyle = getMap("archivingSwipeActionStyle")
|
|
110
|
+
|
|
105
111
|
val unreadIndicatorStyle = getMap("unreadIndicatorStyle")
|
|
106
112
|
val loadingIndicatorColor = getString("loadingIndicatorColor")
|
|
107
113
|
|
|
@@ -109,12 +115,39 @@ class CourierInboxViewManager : SimpleViewManager<CourierInbox>() {
|
|
|
109
115
|
val timeStyle = getMap("timeStyle")
|
|
110
116
|
val bodyStyle = getMap("bodyStyle")
|
|
111
117
|
val infoViewStyle = getMap("infoViewStyle")
|
|
112
|
-
val buttonStyles = getMap("
|
|
118
|
+
val buttonStyles = getMap("buttonStyle")
|
|
113
119
|
|
|
114
120
|
val context = view.context
|
|
115
121
|
|
|
116
122
|
return CourierInboxTheme(
|
|
117
123
|
brandId = brandId,
|
|
124
|
+
tabIndicatorColor = tabIndicatorColor?.toColor(),
|
|
125
|
+
tabStyle = tabStyle?.toTabStyle(context) ?: CourierStyles.Inbox.TabStyle(
|
|
126
|
+
selected = CourierStyles.Inbox.TabItemStyle(
|
|
127
|
+
font = CourierStyles.Font(
|
|
128
|
+
sizeInSp = 18
|
|
129
|
+
),
|
|
130
|
+
indicator = CourierStyles.Inbox.TabIndicatorStyle(
|
|
131
|
+
font = CourierStyles.Font(
|
|
132
|
+
sizeInSp = 14
|
|
133
|
+
),
|
|
134
|
+
color = null
|
|
135
|
+
)
|
|
136
|
+
),
|
|
137
|
+
unselected = CourierStyles.Inbox.TabItemStyle(
|
|
138
|
+
font = CourierStyles.Font(
|
|
139
|
+
sizeInSp = 18
|
|
140
|
+
),
|
|
141
|
+
indicator = CourierStyles.Inbox.TabIndicatorStyle(
|
|
142
|
+
font = CourierStyles.Font(
|
|
143
|
+
sizeInSp = 14
|
|
144
|
+
),
|
|
145
|
+
color = null
|
|
146
|
+
)
|
|
147
|
+
)
|
|
148
|
+
),
|
|
149
|
+
readingSwipeActionStyle = readingSwipeActionStyle?.toReadingSwipeActionStyle() ?: CourierStyles.Inbox.ReadingSwipeActionStyle(),
|
|
150
|
+
archivingSwipeActionStyle = archivingSwipeActionStyle?.toArchivingSwipeActionStyle() ?: CourierStyles.Inbox.ArchivingSwipeActionStyle(),
|
|
118
151
|
unreadIndicatorStyle = unreadIndicatorStyle?.toUnreadIndicatorStyle() ?: CourierStyles.Inbox.UnreadIndicatorStyle(),
|
|
119
152
|
loadingIndicatorColor = loadingIndicatorColor?.toColor(),
|
|
120
153
|
titleStyle = titleStyle?.toTextStyle(context) ?: CourierStyles.Inbox.TextStyle(
|
|
@@ -154,6 +187,69 @@ class CourierInboxViewManager : SimpleViewManager<CourierInbox>() {
|
|
|
154
187
|
|
|
155
188
|
}
|
|
156
189
|
|
|
190
|
+
private fun ReadableMap.toTabStyle(context: Context): CourierStyles.Inbox.TabStyle {
|
|
191
|
+
|
|
192
|
+
val selected = getMap("selected")
|
|
193
|
+
val unselected = getMap("unselected")
|
|
194
|
+
|
|
195
|
+
return CourierStyles.Inbox.TabStyle(
|
|
196
|
+
selected = selected?.toTabItemStyle(context) ?: CourierStyles.Inbox.TabItemStyle(
|
|
197
|
+
font = CourierStyles.Font(
|
|
198
|
+
sizeInSp = 18
|
|
199
|
+
),
|
|
200
|
+
indicator = CourierStyles.Inbox.TabIndicatorStyle(
|
|
201
|
+
font = CourierStyles.Font(
|
|
202
|
+
sizeInSp = 14
|
|
203
|
+
),
|
|
204
|
+
color = null
|
|
205
|
+
)
|
|
206
|
+
),
|
|
207
|
+
unselected = unselected?.toTabItemStyle(context) ?: CourierStyles.Inbox.TabItemStyle(
|
|
208
|
+
font = CourierStyles.Font(
|
|
209
|
+
sizeInSp = 18
|
|
210
|
+
),
|
|
211
|
+
indicator = CourierStyles.Inbox.TabIndicatorStyle(
|
|
212
|
+
font = CourierStyles.Font(
|
|
213
|
+
sizeInSp = 14
|
|
214
|
+
),
|
|
215
|
+
color = null
|
|
216
|
+
)
|
|
217
|
+
),
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private fun ReadableMap.toTabItemStyle(context: Context): CourierStyles.Inbox.TabItemStyle {
|
|
223
|
+
|
|
224
|
+
val font = getMap("font")
|
|
225
|
+
val indicator = getMap("indicator")
|
|
226
|
+
|
|
227
|
+
return CourierStyles.Inbox.TabItemStyle(
|
|
228
|
+
font = font?.toFont(context) ?: CourierStyles.Font(
|
|
229
|
+
sizeInSp = 18
|
|
230
|
+
),
|
|
231
|
+
indicator = indicator?.toTabIndicatorStyle(context) ?: CourierStyles.Inbox.TabIndicatorStyle(
|
|
232
|
+
font = CourierStyles.Font(
|
|
233
|
+
sizeInSp = 14
|
|
234
|
+
),
|
|
235
|
+
color = null
|
|
236
|
+
),
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
private fun ReadableMap.toTabIndicatorStyle(context: Context): CourierStyles.Inbox.TabIndicatorStyle {
|
|
242
|
+
|
|
243
|
+
val font = getMap("font")
|
|
244
|
+
val color = getString("color")
|
|
245
|
+
|
|
246
|
+
return CourierStyles.Inbox.TabIndicatorStyle(
|
|
247
|
+
font = font?.toFont(context) ?: CourierStyles.Font(),
|
|
248
|
+
color = color?.toColor(),
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
}
|
|
252
|
+
|
|
157
253
|
private fun ReadableMap.toUnreadIndicatorStyle(): CourierStyles.Inbox.UnreadIndicatorStyle {
|
|
158
254
|
|
|
159
255
|
val indicator = getString("indicator")
|
|
@@ -172,6 +268,39 @@ class CourierInboxViewManager : SimpleViewManager<CourierInbox>() {
|
|
|
172
268
|
|
|
173
269
|
}
|
|
174
270
|
|
|
271
|
+
private fun ReadableMap.toReadingSwipeActionStyle(): CourierStyles.Inbox.ReadingSwipeActionStyle? {
|
|
272
|
+
|
|
273
|
+
val readDict = getMap("read") ?: return null
|
|
274
|
+
val unreadDict = getMap("unread") ?: return null
|
|
275
|
+
|
|
276
|
+
val read = readDict.toSwipeActionStyle() ?: return null
|
|
277
|
+
val unread = unreadDict.toSwipeActionStyle() ?: return null
|
|
278
|
+
|
|
279
|
+
return CourierStyles.Inbox.ReadingSwipeActionStyle(
|
|
280
|
+
read = read,
|
|
281
|
+
unread = unread
|
|
282
|
+
)
|
|
283
|
+
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
private fun ReadableMap.toArchivingSwipeActionStyle(): CourierStyles.Inbox.ArchivingSwipeActionStyle? {
|
|
287
|
+
// TODO: Icon
|
|
288
|
+
|
|
289
|
+
val archiveDict = getMap("archive") ?: return null
|
|
290
|
+
val archive = archiveDict.toSwipeActionStyle() ?: return null
|
|
291
|
+
|
|
292
|
+
return CourierStyles.Inbox.ArchivingSwipeActionStyle(archive = archive)
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
private fun ReadableMap.toSwipeActionStyle(): CourierStyles.Inbox.SwipeActionStyle? {
|
|
296
|
+
// TODO: Icon
|
|
297
|
+
|
|
298
|
+
val colorString = getString("color") ?: return null
|
|
299
|
+
val color = colorString.toColor()
|
|
300
|
+
|
|
301
|
+
return CourierStyles.Inbox.SwipeActionStyle(icon = null, color = color)
|
|
302
|
+
}
|
|
303
|
+
|
|
175
304
|
private fun ReadableMap.toButtonStyle(context: Context): CourierStyles.Inbox.ButtonStyle {
|
|
176
305
|
|
|
177
306
|
val unread = getMap("unread")
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
package com.courierreactnative
|
|
2
2
|
|
|
3
|
+
import android.annotation.SuppressLint
|
|
3
4
|
import android.content.Intent
|
|
4
5
|
import android.os.Bundle
|
|
5
6
|
import com.courier.android.Courier
|
|
6
|
-
import com.courier.android.models.CourierAgent
|
|
7
7
|
import com.courier.android.utils.getLastDeliveredMessage
|
|
8
8
|
import com.courier.android.utils.pushNotification
|
|
9
9
|
import com.courier.android.utils.trackPushNotificationClick
|
|
@@ -15,13 +15,13 @@ open class CourierReactNativeActivity : ReactActivity() {
|
|
|
15
15
|
|
|
16
16
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
17
17
|
|
|
18
|
+
// Update the user agent
|
|
19
|
+
Courier.agent = Utils.COURIER_AGENT
|
|
20
|
+
|
|
18
21
|
// Starts the Courier SDK
|
|
19
22
|
// Used to ensure shared preferences works properly
|
|
20
23
|
Courier.initialize(this)
|
|
21
24
|
|
|
22
|
-
// Update the user agent
|
|
23
|
-
Courier.agent = CourierAgent.ReactNativeAndroid(version = "4.1.0")
|
|
24
|
-
|
|
25
25
|
super.onCreate(savedInstanceState)
|
|
26
26
|
|
|
27
27
|
// See if there is a pending click event
|
|
@@ -45,6 +45,7 @@ open class CourierReactNativeActivity : ReactActivity() {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
@SuppressLint("VisibleForTests")
|
|
48
49
|
private fun postPushNotificationDelivered(message: RemoteMessage) {
|
|
49
50
|
reactInstanceManager.currentReactContext?.sendEvent(
|
|
50
51
|
eventName = CourierEvents.Push.DELIVERED_EVENT,
|
|
@@ -52,6 +53,7 @@ open class CourierReactNativeActivity : ReactActivity() {
|
|
|
52
53
|
)
|
|
53
54
|
}
|
|
54
55
|
|
|
56
|
+
@SuppressLint("VisibleForTests")
|
|
55
57
|
private fun postPushNotificationClicked(message: RemoteMessage) {
|
|
56
58
|
reactInstanceManager.currentReactContext?.sendEvent(
|
|
57
59
|
eventName = CourierEvents.Push.CLICKED_EVENT,
|
|
@@ -3,7 +3,7 @@ package com.courierreactnative
|
|
|
3
3
|
import com.courier.android.Courier
|
|
4
4
|
import com.courier.android.models.CourierAuthenticationListener
|
|
5
5
|
import com.courier.android.models.CourierInboxListener
|
|
6
|
-
import com.courier.android.models.
|
|
6
|
+
import com.courier.android.models.InboxMessageSet
|
|
7
7
|
import com.courier.android.models.remove
|
|
8
8
|
import com.courier.android.modules.addAuthenticationListener
|
|
9
9
|
import com.courier.android.modules.addInboxListener
|
|
@@ -24,10 +24,12 @@ import com.courier.android.modules.tenantId
|
|
|
24
24
|
import com.courier.android.modules.tokens
|
|
25
25
|
import com.courier.android.modules.unreadMessage
|
|
26
26
|
import com.courier.android.modules.userId
|
|
27
|
+
import com.courier.android.ui.inbox.InboxMessageFeed
|
|
27
28
|
import com.facebook.react.bridge.Arguments
|
|
28
29
|
import com.facebook.react.bridge.Promise
|
|
29
30
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
30
31
|
import com.facebook.react.bridge.ReactMethod
|
|
32
|
+
import com.facebook.react.bridge.WritableMap
|
|
31
33
|
import kotlinx.coroutines.CoroutineScope
|
|
32
34
|
import kotlinx.coroutines.Dispatchers
|
|
33
35
|
import kotlinx.coroutines.launch
|
|
@@ -235,39 +237,80 @@ class CourierSharedModule(reactContext: ReactApplicationContext): ReactNativeMod
|
|
|
235
237
|
}
|
|
236
238
|
|
|
237
239
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
238
|
-
fun addInboxListener(loadingId: String, errorId: String,
|
|
240
|
+
fun addInboxListener(loadingId: String, errorId: String, unreadCountId: String, feedId: String, archiveId: String, pageAddedId: String, messageChangedId: String, messageAddedId: String, messageRemovedId: String): String {
|
|
239
241
|
|
|
240
242
|
val listener = Courier.shared.addInboxListener(
|
|
241
|
-
|
|
242
|
-
|
|
243
|
+
onLoading = {
|
|
243
244
|
reactApplicationContext.sendEvent(
|
|
244
245
|
eventName = loadingId,
|
|
245
246
|
value = null
|
|
246
247
|
)
|
|
247
|
-
|
|
248
248
|
},
|
|
249
249
|
onError = { e ->
|
|
250
|
-
|
|
251
250
|
reactApplicationContext.sendEvent(
|
|
252
251
|
eventName = errorId,
|
|
253
252
|
value = e.message ?: "Courier Inbox Error"
|
|
254
253
|
)
|
|
255
|
-
|
|
256
254
|
},
|
|
257
|
-
|
|
258
|
-
|
|
255
|
+
onUnreadCountChanged = { unreadCount ->
|
|
256
|
+
reactApplicationContext.sendEvent(
|
|
257
|
+
eventName = unreadCountId,
|
|
258
|
+
value = unreadCount
|
|
259
|
+
)
|
|
260
|
+
},
|
|
261
|
+
onFeedChanged = { messageSet ->
|
|
262
|
+
reactApplicationContext.sendEvent(
|
|
263
|
+
eventName = feedId,
|
|
264
|
+
value = messageSet.toJson()
|
|
265
|
+
)
|
|
266
|
+
},
|
|
267
|
+
onArchiveChanged = { messageSet ->
|
|
268
|
+
reactApplicationContext.sendEvent(
|
|
269
|
+
eventName = feedId,
|
|
270
|
+
value = messageSet.toJson()
|
|
271
|
+
)
|
|
272
|
+
},
|
|
273
|
+
onPageAdded = { feed, messageSet ->
|
|
259
274
|
val json = Arguments.createMap()
|
|
260
|
-
json.
|
|
261
|
-
json.
|
|
262
|
-
json.putInt("totalMessageCount",
|
|
263
|
-
json.putBoolean("canPaginate", canPaginate)
|
|
264
|
-
|
|
275
|
+
json.putString("feed", if (feed == InboxMessageFeed.FEED) "feed" else "archived")
|
|
276
|
+
json.putArray("messages", messageSet.messages.map { it.toJson() }.toWritableArray())
|
|
277
|
+
json.putInt("totalMessageCount", messageSet.totalCount)
|
|
278
|
+
json.putBoolean("canPaginate", messageSet.canPaginate)
|
|
265
279
|
reactApplicationContext.sendEvent(
|
|
266
|
-
eventName =
|
|
280
|
+
eventName = pageAddedId,
|
|
267
281
|
value = json
|
|
268
282
|
)
|
|
269
|
-
|
|
270
|
-
|
|
283
|
+
},
|
|
284
|
+
onMessageAdded = { feed, index, message ->
|
|
285
|
+
val json = Arguments.createMap()
|
|
286
|
+
json.putString("feed", if (feed == InboxMessageFeed.FEED) "feed" else "archived")
|
|
287
|
+
json.putInt("index", index)
|
|
288
|
+
json.putString("message", message.toJson())
|
|
289
|
+
reactApplicationContext.sendEvent(
|
|
290
|
+
eventName = messageAddedId,
|
|
291
|
+
value = json
|
|
292
|
+
)
|
|
293
|
+
},
|
|
294
|
+
onMessageChanged = { feed, index, message ->
|
|
295
|
+
val json = Arguments.createMap()
|
|
296
|
+
json.putString("feed", if (feed == InboxMessageFeed.FEED) "feed" else "archived")
|
|
297
|
+
json.putInt("index", index)
|
|
298
|
+
json.putString("message", message.toJson())
|
|
299
|
+
reactApplicationContext.sendEvent(
|
|
300
|
+
eventName = messageAddedId,
|
|
301
|
+
value = json
|
|
302
|
+
)
|
|
303
|
+
},
|
|
304
|
+
onMessageRemoved = { feed, index, message ->
|
|
305
|
+
val json = Arguments.createMap()
|
|
306
|
+
json.putString("feed", if (feed == InboxMessageFeed.FEED) "feed" else "archived")
|
|
307
|
+
json.putInt("index", index)
|
|
308
|
+
json.putString("message", message.toJson())
|
|
309
|
+
reactApplicationContext.sendEvent(
|
|
310
|
+
eventName = messageAddedId,
|
|
311
|
+
value = json
|
|
312
|
+
)
|
|
313
|
+
},
|
|
271
314
|
)
|
|
272
315
|
|
|
273
316
|
// Add listener
|
|
@@ -278,6 +321,14 @@ class CourierSharedModule(reactContext: ReactApplicationContext): ReactNativeMod
|
|
|
278
321
|
|
|
279
322
|
}
|
|
280
323
|
|
|
324
|
+
private fun InboxMessageSet.toJson(): WritableMap? {
|
|
325
|
+
val json = Arguments.createMap()
|
|
326
|
+
json.putArray("messages", messages.toList().map { it.toJson() }.toWritableArray())
|
|
327
|
+
json.putInt("totalMessageCount", totalCount)
|
|
328
|
+
json.putBoolean("canPaginate", canPaginate)
|
|
329
|
+
return json
|
|
330
|
+
}
|
|
331
|
+
|
|
281
332
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
282
333
|
fun removeInboxListener(listenerId: String): String {
|
|
283
334
|
val listener = inboxListeners[listenerId]
|
|
@@ -300,10 +351,10 @@ class CourierSharedModule(reactContext: ReactApplicationContext): ReactNativeMod
|
|
|
300
351
|
}
|
|
301
352
|
|
|
302
353
|
@ReactMethod
|
|
303
|
-
fun fetchNextPageOfMessages(promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
|
|
354
|
+
fun fetchNextPageOfMessages(promise: Promise, inboxMessageFeed: String) = CoroutineScope(Dispatchers.Main).launch {
|
|
304
355
|
try {
|
|
305
|
-
val
|
|
306
|
-
promise.resolve(
|
|
356
|
+
val messageSet = Courier.shared.fetchNextInboxPage(if (inboxMessageFeed == "archived") InboxMessageFeed.ARCHIVE else InboxMessageFeed.FEED)
|
|
357
|
+
promise.resolve(messageSet?.toJson())
|
|
307
358
|
} catch (e: Exception) {
|
|
308
359
|
promise.apiError(e)
|
|
309
360
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
package com.courierreactnative
|
|
2
2
|
|
|
3
3
|
import com.courier.android.Courier
|
|
4
|
-
import com.courier.android.models.CourierAgent
|
|
5
4
|
import com.facebook.react.ReactActivity
|
|
6
5
|
import com.facebook.react.bridge.Promise
|
|
7
6
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
@@ -17,7 +16,7 @@ abstract class ReactNativeModule(val tag: String, private val name: String, reac
|
|
|
17
16
|
|
|
18
17
|
// User Agent is used to ensure we know the SDK
|
|
19
18
|
// the requests come from
|
|
20
|
-
Courier.agent =
|
|
19
|
+
Courier.agent = Utils.COURIER_AGENT
|
|
21
20
|
|
|
22
21
|
}
|
|
23
22
|
|
|
@@ -4,11 +4,7 @@ import android.content.Context
|
|
|
4
4
|
import android.graphics.Color
|
|
5
5
|
import android.graphics.Typeface
|
|
6
6
|
import androidx.recyclerview.widget.DividerItemDecoration
|
|
7
|
-
import com.courier.android.models.
|
|
8
|
-
import com.courier.android.models.CourierUserPreferences
|
|
9
|
-
import com.courier.android.models.InboxAction
|
|
10
|
-
import com.courier.android.models.InboxMessage
|
|
11
|
-
import com.courier.android.models.Paging
|
|
7
|
+
import com.courier.android.models.CourierAgent
|
|
12
8
|
import com.courier.android.ui.CourierStyles
|
|
13
9
|
import com.facebook.react.bridge.Arguments
|
|
14
10
|
import com.facebook.react.bridge.ReactContext
|
|
@@ -18,151 +14,16 @@ import com.facebook.react.bridge.WritableMap
|
|
|
18
14
|
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
19
15
|
import com.google.gson.GsonBuilder
|
|
20
16
|
|
|
21
|
-
internal
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
internal fun CourierUserPreferences.toWritableMap(): WritableMap {
|
|
26
|
-
|
|
27
|
-
val map = Arguments.createMap()
|
|
28
|
-
|
|
29
|
-
val itemsArray = Arguments.createArray()
|
|
30
|
-
items.forEach { topic ->
|
|
31
|
-
itemsArray.pushMap(topic.toWritableMap())
|
|
32
|
-
}
|
|
33
|
-
map.putArray("items", itemsArray)
|
|
34
|
-
|
|
35
|
-
map.putMap("paging", paging.toWritableMap())
|
|
36
|
-
|
|
37
|
-
return map
|
|
38
|
-
|
|
17
|
+
internal object Utils {
|
|
18
|
+
val COURIER_AGENT = CourierAgent.ReactNativeAndroid(version = "5.0.0")
|
|
39
19
|
}
|
|
40
20
|
|
|
41
|
-
internal fun
|
|
42
|
-
|
|
43
|
-
val map = Arguments.createMap()
|
|
44
|
-
map.putString("defaultStatus", defaultStatus.value)
|
|
45
|
-
map.putBoolean("hasCustomRouting", hasCustomRouting)
|
|
46
|
-
map.putString("status", status.value)
|
|
47
|
-
map.putString("topicId", topicId)
|
|
48
|
-
map.putString("topicName", topicName)
|
|
49
|
-
map.putString("sectionId", sectionId)
|
|
50
|
-
map.putString("sectionName", sectionName)
|
|
51
|
-
|
|
52
|
-
val actionsArray = Arguments.createArray()
|
|
53
|
-
customRouting.forEach { routing ->
|
|
54
|
-
actionsArray.pushString(routing.value)
|
|
55
|
-
}
|
|
56
|
-
map.putArray("customRouting", actionsArray)
|
|
57
|
-
|
|
58
|
-
return map
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
internal fun Paging.toWritableMap(): WritableMap {
|
|
63
|
-
|
|
64
|
-
val map = Arguments.createMap()
|
|
65
|
-
|
|
66
|
-
cursor?.let {
|
|
67
|
-
map.putString("cursor", it)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
map.putBoolean("more", more)
|
|
71
|
-
|
|
72
|
-
return map
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
@JvmName("toWritableArrayInboxMessage")
|
|
77
|
-
internal fun List<InboxMessage>.toWritableArray(): WritableArray {
|
|
78
|
-
|
|
79
|
-
val messagesArray = Arguments.createArray()
|
|
80
|
-
|
|
81
|
-
forEach { message ->
|
|
82
|
-
messagesArray.pushMap(message.toWritableMap())
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return messagesArray
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
internal fun InboxMessage.toWritableMap(): WritableMap {
|
|
90
|
-
|
|
91
|
-
val map = Arguments.createMap()
|
|
92
|
-
map.putString("messageId", messageId)
|
|
93
|
-
map.putString("title", title)
|
|
94
|
-
map.putString("body", body)
|
|
95
|
-
map.putString("preview", preview)
|
|
96
|
-
map.putString("created", created)
|
|
97
|
-
|
|
98
|
-
actions?.let { actionList ->
|
|
99
|
-
val actionsArray = Arguments.createArray()
|
|
100
|
-
actionList.forEach { action ->
|
|
101
|
-
actionsArray.pushMap(action.toWritableMap())
|
|
102
|
-
}
|
|
103
|
-
map.putArray("actions", actionsArray)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
map.putMap("data", data.toWritableMap())
|
|
107
|
-
map.putBoolean("read", isRead)
|
|
108
|
-
map.putBoolean("opened", isOpened)
|
|
109
|
-
map.putBoolean("archived", isArchived)
|
|
110
|
-
|
|
111
|
-
val trackingIds = Arguments.createMap()
|
|
112
|
-
trackingIds.putString("clickTrackingId", clickTrackingId)
|
|
113
|
-
|
|
114
|
-
map.putMap("trackingIds", trackingIds)
|
|
115
|
-
|
|
116
|
-
return map
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
internal fun InboxAction.toWritableMap(): WritableMap {
|
|
121
|
-
|
|
122
|
-
val map = Arguments.createMap()
|
|
123
|
-
map.putString("content", content)
|
|
124
|
-
map.putString("href", href)
|
|
125
|
-
map.putMap("data", data.toWritableMap())
|
|
126
|
-
|
|
127
|
-
return map
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
internal fun Map<String, Any>?.toWritableMap(): WritableMap {
|
|
132
|
-
val map = Arguments.createMap()
|
|
133
|
-
this?.forEach { (key, value) ->
|
|
134
|
-
when (value) {
|
|
135
|
-
is String -> map.putString(key, value)
|
|
136
|
-
is Int -> map.putInt(key, value)
|
|
137
|
-
is Double -> map.putDouble(key, value)
|
|
138
|
-
is Boolean -> map.putBoolean(key, value)
|
|
139
|
-
is Map<*, *> -> map.putMap(key, (value as? Map<String, Any>).toWritableMap())
|
|
140
|
-
is List<*> -> map.putArray(key, (value as? List<Any>).toWritableArray())
|
|
141
|
-
else -> map.putNull(key)
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return map
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
internal fun List<Any>?.toWritableArray(): WritableArray {
|
|
148
|
-
val array = Arguments.createArray()
|
|
149
|
-
this?.forEach { item ->
|
|
150
|
-
when (item) {
|
|
151
|
-
is String -> array.pushString(item)
|
|
152
|
-
is Int -> array.pushInt(item)
|
|
153
|
-
is Double -> array.pushDouble(item)
|
|
154
|
-
is Boolean -> array.pushBoolean(item)
|
|
155
|
-
is Map<*, *> -> array.pushMap((item as? Map<String, Any>).toWritableMap())
|
|
156
|
-
is List<*> -> array.pushArray((item as? List<Any>).toWritableArray())
|
|
157
|
-
else -> array.pushNull()
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
return array
|
|
21
|
+
internal fun ReactContext.sendEvent(eventName: String, value: Any?) {
|
|
22
|
+
getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java).emit(eventName, value)
|
|
161
23
|
}
|
|
162
24
|
|
|
163
25
|
internal fun String.toDivider(context: Context): DividerItemDecoration? = if (this == "vertical") DividerItemDecoration(context, DividerItemDecoration.VERTICAL) else null
|
|
164
26
|
|
|
165
|
-
|
|
166
27
|
internal fun String.toColor(): Int = Color.parseColor(this)
|
|
167
28
|
|
|
168
29
|
internal fun String.toFont(context: Context): Typeface? {
|
|
@@ -215,6 +76,38 @@ internal fun ReadableMap.toInfoViewStyle(context: Context): CourierStyles.InfoVi
|
|
|
215
76
|
|
|
216
77
|
}
|
|
217
78
|
|
|
79
|
+
internal fun Map<String, Any>?.toWritableMap(): WritableMap {
|
|
80
|
+
val map = Arguments.createMap()
|
|
81
|
+
this?.forEach { (key, value) ->
|
|
82
|
+
when (value) {
|
|
83
|
+
is String -> map.putString(key, value)
|
|
84
|
+
is Int -> map.putInt(key, value)
|
|
85
|
+
is Double -> map.putDouble(key, value)
|
|
86
|
+
is Boolean -> map.putBoolean(key, value)
|
|
87
|
+
is Map<*, *> -> map.putMap(key, (value as? Map<String, Any>).toWritableMap())
|
|
88
|
+
is List<*> -> map.putArray(key, (value as? List<Any>).toWritableArray())
|
|
89
|
+
else -> map.putNull(key)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return map
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
internal fun List<Any>?.toWritableArray(): WritableArray {
|
|
96
|
+
val array = Arguments.createArray()
|
|
97
|
+
this?.forEach { item ->
|
|
98
|
+
when (item) {
|
|
99
|
+
is String -> array.pushString(item)
|
|
100
|
+
is Int -> array.pushInt(item)
|
|
101
|
+
is Double -> array.pushDouble(item)
|
|
102
|
+
is Boolean -> array.pushBoolean(item)
|
|
103
|
+
is Map<*, *> -> array.pushMap((item as? Map<String, Any>).toWritableMap())
|
|
104
|
+
is List<*> -> array.pushArray((item as? List<Any>).toWritableArray())
|
|
105
|
+
else -> array.pushNull()
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return array
|
|
109
|
+
}
|
|
110
|
+
|
|
218
111
|
internal fun Any.toJson(): String {
|
|
219
112
|
return GsonBuilder().setPrettyPrinting().create().toJson(this)
|
|
220
113
|
}
|
|
@@ -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", "
|
|
20
|
+
s.dependency "Courier_iOS", "5.2.0"
|
|
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.
|