@trycourier/courier-react-native 2.5.0 → 3.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 +187 -0
- package/android/src/main/java/com/courierreactnative/CourierPreferencesViewManager.kt +128 -0
- package/android/src/main/java/com/courierreactnative/CourierReactNativePackage.kt +3 -1
- package/android/src/main/java/com/courierreactnative/Extensions.kt +68 -1
- package/courier-react-native.podspec +1 -1
- package/ios/{CourierReactNativeViewManager.m → CourierInboxReactNativeManager.m} +1 -1
- package/ios/CourierInboxReactNativeManager.swift +159 -0
- package/ios/CourierPreferencesReactNativeManager.m +11 -0
- package/ios/CourierPreferencesReactNativeManager.swift +140 -0
- package/ios/CourierReactNativeModule.swift +50 -36
- package/ios/Utils.swift +70 -0
- package/lib/commonjs/index.js +54 -36
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/Android_CourierSheet.js +6 -0
- package/lib/commonjs/models/Android_CourierSheet.js.map +1 -0
- package/lib/commonjs/models/CourierButton.js +6 -0
- package/lib/commonjs/models/CourierButton.js.map +1 -0
- package/lib/commonjs/models/CourierFont.js +2 -0
- package/lib/commonjs/models/CourierFont.js.map +1 -0
- package/lib/commonjs/models/CourierInboxTheme.js +4 -0
- package/lib/commonjs/models/CourierInfoViewStyle.js +6 -0
- package/lib/commonjs/models/CourierInfoViewStyle.js.map +1 -0
- package/lib/commonjs/models/CourierPreferencesTheme.js +6 -0
- package/lib/commonjs/models/CourierPreferencesTheme.js.map +1 -0
- package/lib/commonjs/models/iOS_CourierCell.js +2 -0
- package/lib/commonjs/models/iOS_CourierCell.js.map +1 -0
- package/lib/commonjs/models/iOS_CourierSheet.js +6 -0
- package/lib/commonjs/models/iOS_CourierSheet.js.map +1 -0
- package/lib/commonjs/views/CourierInboxView.js +1 -1
- package/lib/commonjs/views/CourierInboxView.js.map +1 -1
- package/lib/commonjs/views/CourierPreferencesView.js +37 -0
- package/lib/commonjs/views/CourierPreferencesView.js.map +1 -0
- package/lib/module/index.js +25 -25
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/Android_CourierSheet.js +2 -0
- package/lib/module/models/Android_CourierSheet.js.map +1 -0
- package/lib/module/models/CourierButton.js +2 -0
- package/lib/module/models/CourierButton.js.map +1 -0
- package/lib/module/models/CourierFont.js +2 -0
- package/lib/module/models/CourierFont.js.map +1 -0
- package/lib/module/models/CourierInboxTheme.js +1 -1
- package/lib/module/models/CourierInfoViewStyle.js +2 -0
- package/lib/module/models/CourierInfoViewStyle.js.map +1 -0
- package/lib/module/models/CourierPreferencesTheme.js +2 -0
- package/lib/module/models/CourierPreferencesTheme.js.map +1 -0
- package/lib/module/models/iOS_CourierCell.js +2 -0
- package/lib/module/models/iOS_CourierCell.js.map +1 -0
- package/lib/module/models/iOS_CourierSheet.js +2 -0
- package/lib/module/models/iOS_CourierSheet.js.map +1 -0
- package/lib/module/views/CourierInboxView.js +1 -1
- package/lib/module/views/CourierInboxView.js.map +1 -1
- package/lib/module/views/CourierPreferencesView.js +29 -0
- package/lib/module/views/CourierPreferencesView.js.map +1 -0
- package/lib/typescript/index.d.ts +9 -3
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/models/Android_CourierSheet.d.ts +7 -0
- package/lib/typescript/models/Android_CourierSheet.d.ts.map +1 -0
- package/lib/typescript/models/CourierButton.d.ts +7 -0
- package/lib/typescript/models/CourierButton.d.ts.map +1 -0
- package/lib/typescript/models/CourierFont.d.ts +6 -0
- package/lib/typescript/models/CourierFont.d.ts.map +1 -0
- package/lib/typescript/models/CourierInboxTheme.d.ts +9 -19
- package/lib/typescript/models/CourierInboxTheme.d.ts.map +1 -1
- package/lib/typescript/models/CourierInfoViewStyle.d.ts +7 -0
- package/lib/typescript/models/CourierInfoViewStyle.d.ts.map +1 -0
- package/lib/typescript/models/CourierPreferencesTheme.d.ts +35 -0
- package/lib/typescript/models/CourierPreferencesTheme.d.ts.map +1 -0
- package/lib/typescript/models/CourierUserPreferencesTopic.d.ts +3 -1
- package/lib/typescript/models/CourierUserPreferencesTopic.d.ts.map +1 -1
- package/lib/typescript/models/iOS_CourierCell.d.ts +12 -0
- package/lib/typescript/models/iOS_CourierCell.d.ts.map +1 -0
- package/lib/typescript/models/iOS_CourierSheet.d.ts +6 -0
- package/lib/typescript/models/iOS_CourierSheet.d.ts.map +1 -0
- package/lib/typescript/views/CourierPreferencesView.d.ts +15 -0
- package/lib/typescript/views/CourierPreferencesView.d.ts.map +1 -0
- package/package.json +5 -2
- package/src/index.tsx +27 -27
- package/src/models/Android_CourierSheet.tsx +7 -0
- package/src/models/CourierButton.tsx +7 -0
- package/src/models/CourierFont.tsx +5 -0
- package/src/models/CourierInboxTheme.tsx +9 -21
- package/src/models/CourierInfoViewStyle.tsx +7 -0
- package/src/models/CourierPreferencesTheme.tsx +34 -0
- package/src/models/CourierUserPreferencesTopic.tsx +3 -1
- package/src/models/iOS_CourierCell.tsx +6 -0
- package/src/models/iOS_CourierSheet.tsx +6 -0
- package/src/views/CourierInboxView.tsx +12 -12
- package/src/views/CourierPreferencesView.tsx +53 -0
- package/android/src/main/java/com/courierreactnative/CourierReactNativeViewManager.kt +0 -225
- package/ios/CourierAuthenticationListenerWrapper.swift +0 -14
- package/ios/CourierInboxListenerWrapper.swift +0 -24
- package/ios/CourierReactNativeViewManager.swift +0 -302
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:3.2.6'
|
|
105
105
|
api 'androidx.recyclerview:recyclerview:1.3.2'
|
|
106
106
|
|
|
107
107
|
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
package com.courierreactnative
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.util.AttributeSet
|
|
5
|
+
import android.view.View
|
|
6
|
+
import com.courier.android.ui.CourierStyles
|
|
7
|
+
import com.courier.android.ui.inbox.CourierInbox
|
|
8
|
+
import com.courier.android.ui.inbox.CourierInboxTheme
|
|
9
|
+
import com.facebook.react.bridge.Arguments
|
|
10
|
+
import com.facebook.react.bridge.ReadableMap
|
|
11
|
+
import com.facebook.react.uimanager.SimpleViewManager
|
|
12
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
13
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
|
14
|
+
|
|
15
|
+
internal class CourierReactNativeInboxView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : CourierInbox(context, attrs, defStyleAttr) {
|
|
16
|
+
|
|
17
|
+
override fun requestLayout() {
|
|
18
|
+
super.requestLayout()
|
|
19
|
+
post(measureAndLayout)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private val measureAndLayout = Runnable {
|
|
23
|
+
measure(
|
|
24
|
+
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
|
|
25
|
+
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
|
|
26
|
+
)
|
|
27
|
+
layout(left, top, right, bottom)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
class CourierInboxViewManager : SimpleViewManager<CourierInbox>() {
|
|
33
|
+
|
|
34
|
+
private var themedReactContext: ThemedReactContext? = null
|
|
35
|
+
|
|
36
|
+
private companion object {
|
|
37
|
+
const val ON_CLICK_MESSAGE_AT_INDEX = "courierClickMessageAtIndex"
|
|
38
|
+
const val ON_CLICK_ACTION_AT_INDEX = "courierClickActionAtIndex"
|
|
39
|
+
const val ON_SCROLL = "courierScrollInbox"
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
override fun getName() = "CourierInboxView"
|
|
43
|
+
|
|
44
|
+
override fun createViewInstance(reactContext: ThemedReactContext): CourierInbox {
|
|
45
|
+
themedReactContext = reactContext
|
|
46
|
+
return CourierReactNativeInboxView(reactContext)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@ReactProp(name = "onClickInboxMessageAtIndex")
|
|
50
|
+
fun setOnClickInboxMessageAtIndex(view: CourierInbox, callback: Boolean) {
|
|
51
|
+
|
|
52
|
+
view.setOnClickMessageListener { message, index ->
|
|
53
|
+
val map = Arguments.createMap()
|
|
54
|
+
map.putMap("message", message.toWritableMap())
|
|
55
|
+
map.putInt("index", index)
|
|
56
|
+
themedReactContext?.sendEvent(ON_CLICK_MESSAGE_AT_INDEX, map)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@ReactProp(name = "onClickInboxActionForMessageAtIndex")
|
|
62
|
+
fun setOnClickInboxActionForMessageAtIndex(view: CourierInbox, callback: Boolean) {
|
|
63
|
+
|
|
64
|
+
view.setOnClickActionListener { action, message, index ->
|
|
65
|
+
val map = Arguments.createMap()
|
|
66
|
+
map.putMap("action", action.toWritableMap())
|
|
67
|
+
map.putMap("message", message.toWritableMap())
|
|
68
|
+
map.putInt("index", index)
|
|
69
|
+
themedReactContext?.sendEvent(ON_CLICK_ACTION_AT_INDEX, map)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@ReactProp(name = "onScrollInbox")
|
|
75
|
+
fun setOnScrollInbox(view: CourierInbox, callback: Boolean) {
|
|
76
|
+
|
|
77
|
+
view.setOnScrollInboxListener { offsetInDp ->
|
|
78
|
+
|
|
79
|
+
val offset = Arguments.createMap()
|
|
80
|
+
offset.putInt("y", offsetInDp)
|
|
81
|
+
offset.putInt("x", 0)
|
|
82
|
+
|
|
83
|
+
val map = Arguments.createMap()
|
|
84
|
+
map.putMap("contentOffset", offset)
|
|
85
|
+
|
|
86
|
+
themedReactContext?.sendEvent(ON_SCROLL, map)
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@ReactProp(name = "theme")
|
|
93
|
+
fun setTheme(view: CourierInbox, theme: ReadableMap) {
|
|
94
|
+
view.lightTheme = theme.getMap("light")?.toTheme(view) ?: CourierInboxTheme.DEFAULT_LIGHT
|
|
95
|
+
view.darkTheme = theme.getMap("dark")?.toTheme(view) ?: CourierInboxTheme.DEFAULT_DARK
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private fun ReadableMap.toTheme(view: View): CourierInboxTheme {
|
|
99
|
+
|
|
100
|
+
val android = getMap("android")
|
|
101
|
+
val dividerItemDecoration = android?.getString("dividerItemDecoration")
|
|
102
|
+
|
|
103
|
+
val brandId = getString("brandId")
|
|
104
|
+
|
|
105
|
+
val unreadIndicatorStyle = getMap("unreadIndicatorStyle")
|
|
106
|
+
val loadingIndicatorColor = getString("loadingIndicatorColor")
|
|
107
|
+
|
|
108
|
+
val titleStyle = getMap("titleStyle")
|
|
109
|
+
val timeStyle = getMap("timeStyle")
|
|
110
|
+
val bodyStyle = getMap("bodyStyle")
|
|
111
|
+
val infoViewStyle = getMap("infoViewStyle")
|
|
112
|
+
val buttonStyles = getMap("buttonStyles")
|
|
113
|
+
|
|
114
|
+
val context = view.context
|
|
115
|
+
|
|
116
|
+
return CourierInboxTheme(
|
|
117
|
+
brandId = brandId,
|
|
118
|
+
unreadIndicatorStyle = unreadIndicatorStyle?.toUnreadIndicatorStyle() ?: CourierStyles.Inbox.UnreadIndicatorStyle(),
|
|
119
|
+
loadingIndicatorColor = loadingIndicatorColor?.toColor(),
|
|
120
|
+
titleStyle = titleStyle?.toTextStyle(context) ?: CourierStyles.Inbox.TextStyle(
|
|
121
|
+
unread = CourierStyles.Font(),
|
|
122
|
+
read = CourierStyles.Font(),
|
|
123
|
+
),
|
|
124
|
+
timeStyle = timeStyle?.toTextStyle(context) ?: CourierStyles.Inbox.TextStyle(
|
|
125
|
+
unread = CourierStyles.Font(),
|
|
126
|
+
read = CourierStyles.Font(),
|
|
127
|
+
),
|
|
128
|
+
bodyStyle = bodyStyle?.toTextStyle(context) ?: CourierStyles.Inbox.TextStyle(
|
|
129
|
+
unread = CourierStyles.Font(),
|
|
130
|
+
read = CourierStyles.Font(),
|
|
131
|
+
),
|
|
132
|
+
buttonStyle = buttonStyles?.toButtonStyle(context) ?: CourierStyles.Inbox.ButtonStyle(
|
|
133
|
+
unread = CourierStyles.Button(),
|
|
134
|
+
read = CourierStyles.Button(),
|
|
135
|
+
),
|
|
136
|
+
infoViewStyle = infoViewStyle?.toInfoViewStyle(context) ?: CourierStyles.InfoViewStyle(
|
|
137
|
+
font = CourierStyles.Font(),
|
|
138
|
+
button = CourierStyles.Button(),
|
|
139
|
+
),
|
|
140
|
+
dividerItemDecoration = dividerItemDecoration?.toDivider(context),
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private fun ReadableMap.toTextStyle(context: Context): CourierStyles.Inbox.TextStyle {
|
|
146
|
+
|
|
147
|
+
val unread = getMap("unread")
|
|
148
|
+
val read = getMap("read")
|
|
149
|
+
|
|
150
|
+
return CourierStyles.Inbox.TextStyle(
|
|
151
|
+
unread = unread?.toFont(context) ?: CourierStyles.Font(),
|
|
152
|
+
read = read?.toFont(context) ?: CourierStyles.Font(),
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private fun ReadableMap.toUnreadIndicatorStyle(): CourierStyles.Inbox.UnreadIndicatorStyle {
|
|
158
|
+
|
|
159
|
+
val indicator = getString("indicator")
|
|
160
|
+
val color = getString("color")
|
|
161
|
+
|
|
162
|
+
var style = CourierStyles.Inbox.UnreadIndicator.LINE
|
|
163
|
+
|
|
164
|
+
if (indicator == "dot") {
|
|
165
|
+
style = CourierStyles.Inbox.UnreadIndicator.DOT
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return CourierStyles.Inbox.UnreadIndicatorStyle(
|
|
169
|
+
indicator = style,
|
|
170
|
+
color = color?.toColor(),
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
private fun ReadableMap.toButtonStyle(context: Context): CourierStyles.Inbox.ButtonStyle {
|
|
176
|
+
|
|
177
|
+
val unread = getMap("unread")
|
|
178
|
+
val read = getMap("read")
|
|
179
|
+
|
|
180
|
+
return CourierStyles.Inbox.ButtonStyle(
|
|
181
|
+
unread = unread?.toButton(context) ?: CourierStyles.Button(),
|
|
182
|
+
read = read?.toButton(context) ?: CourierStyles.Button()
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
package com.courierreactnative
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.util.AttributeSet
|
|
5
|
+
import androidx.fragment.app.FragmentActivity
|
|
6
|
+
import com.courier.android.models.CourierPreferenceChannel
|
|
7
|
+
import com.courier.android.ui.CourierStyles
|
|
8
|
+
import com.courier.android.ui.preferences.CourierPreferences
|
|
9
|
+
import com.courier.android.ui.preferences.CourierPreferencesTheme
|
|
10
|
+
import com.facebook.react.bridge.Arguments
|
|
11
|
+
import com.facebook.react.bridge.ReadableMap
|
|
12
|
+
import com.facebook.react.uimanager.SimpleViewManager
|
|
13
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
14
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
|
15
|
+
|
|
16
|
+
internal class CourierReactNativePreferencesView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : CourierPreferences(context, attrs, defStyleAttr) {
|
|
17
|
+
|
|
18
|
+
override fun requestLayout() {
|
|
19
|
+
super.requestLayout()
|
|
20
|
+
post(measureAndLayout)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
private val measureAndLayout = Runnable {
|
|
24
|
+
measure(
|
|
25
|
+
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
|
|
26
|
+
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
|
|
27
|
+
)
|
|
28
|
+
layout(left, top, right, bottom)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
class CourierPreferencesViewManager : SimpleViewManager<CourierPreferences>() {
|
|
34
|
+
|
|
35
|
+
private var themedReactContext: ThemedReactContext? = null
|
|
36
|
+
|
|
37
|
+
private companion object {
|
|
38
|
+
const val ON_ERROR = "courierPreferenceError"
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
override fun getName() = "CourierPreferencesView"
|
|
42
|
+
|
|
43
|
+
override fun createViewInstance(reactContext: ThemedReactContext): CourierPreferences {
|
|
44
|
+
themedReactContext = reactContext
|
|
45
|
+
val activity = reactContext.currentActivity as FragmentActivity
|
|
46
|
+
return CourierReactNativePreferencesView(activity)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@ReactProp(name = "onPreferenceError")
|
|
50
|
+
fun setOnPreferenceError(view: CourierPreferences, callback: Boolean) {
|
|
51
|
+
view.onError = { error ->
|
|
52
|
+
val map = Arguments.createMap()
|
|
53
|
+
map.putString("error", error.message)
|
|
54
|
+
themedReactContext?.sendEvent(ON_ERROR, map)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@ReactProp(name = "mode")
|
|
59
|
+
fun setMode(view: CourierPreferences, theme: ReadableMap) {
|
|
60
|
+
view.mode = theme.toMode()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@ReactProp(name = "theme")
|
|
64
|
+
fun setTheme(view: CourierPreferences, theme: ReadableMap) {
|
|
65
|
+
view.lightTheme = theme.getMap("light")?.toTheme(view) ?: CourierPreferencesTheme.DEFAULT_LIGHT
|
|
66
|
+
view.darkTheme = theme.getMap("dark")?.toTheme(view) ?: CourierPreferencesTheme.DEFAULT_DARK
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private fun ReadableMap.toMode(): CourierPreferences.Mode {
|
|
70
|
+
|
|
71
|
+
val type = getString("type")
|
|
72
|
+
|
|
73
|
+
if (type == "channels") {
|
|
74
|
+
val rawChannels = getArray("channels")?.toArrayList()?.toList() ?: emptyList()
|
|
75
|
+
val channels = rawChannels.map { CourierPreferenceChannel.fromString(it.toString()) }
|
|
76
|
+
return CourierPreferences.Mode.Channels(channels)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return CourierPreferences.Mode.Topic
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private fun ReadableMap.toTheme(view: CourierPreferences): CourierPreferencesTheme {
|
|
84
|
+
|
|
85
|
+
val brandId = getString("brandId")
|
|
86
|
+
val loadingIndicatorColor = getString("loadingIndicatorColor")
|
|
87
|
+
val sectionTitleFont = getMap("sectionTitleFont")
|
|
88
|
+
val topicTitleFont = getMap("topicTitleFont")
|
|
89
|
+
val topicSubtitleFont = getMap("topicSubtitleFont")
|
|
90
|
+
val sheetTitleFont = getMap("sheetTitleFont")
|
|
91
|
+
|
|
92
|
+
val android = getMap("android")
|
|
93
|
+
val topicDividerItemDecoration = android?.getString("topicDividerItemDecoration")
|
|
94
|
+
val sheetDividerItemDecoration = android?.getString("sheetDividerItemDecoration")
|
|
95
|
+
val sheetSettingStyles = android?.getMap("sheetSettingStyles")
|
|
96
|
+
|
|
97
|
+
val context = view.context
|
|
98
|
+
val defaultTheme = CourierPreferencesTheme()
|
|
99
|
+
|
|
100
|
+
return CourierPreferencesTheme(
|
|
101
|
+
brandId = brandId,
|
|
102
|
+
loadingIndicatorColor = loadingIndicatorColor?.toColor(),
|
|
103
|
+
sectionTitleFont = sectionTitleFont?.toFont(context) ?: defaultTheme.sectionTitleFont,
|
|
104
|
+
topicDividerItemDecoration = topicDividerItemDecoration?.toDivider(context),
|
|
105
|
+
topicTitleFont = topicTitleFont?.toFont(context) ?: defaultTheme.topicTitleFont,
|
|
106
|
+
topicSubtitleFont = topicSubtitleFont?.toFont(context) ?: defaultTheme.topicSubtitleFont,
|
|
107
|
+
sheetTitleFont = sheetTitleFont?.toFont(context) ?: defaultTheme.sheetTitleFont,
|
|
108
|
+
sheetDividerItemDecoration = sheetDividerItemDecoration?.toDivider(context),
|
|
109
|
+
sheetSettingStyles = sheetSettingStyles?.toSheetSettingStyles(context, fallback = defaultTheme.sheetSettingStyles) ?: defaultTheme.sheetSettingStyles
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private fun ReadableMap.toSheetSettingStyles(context: Context, fallback: CourierStyles.Preferences.SettingStyles): CourierStyles.Preferences.SettingStyles {
|
|
115
|
+
|
|
116
|
+
val font = getMap("font")
|
|
117
|
+
val toggleThumbColor = getString("toggleThumbColor")
|
|
118
|
+
val toggleTrackColor = getString("toggleTrackColor")
|
|
119
|
+
|
|
120
|
+
return CourierStyles.Preferences.SettingStyles(
|
|
121
|
+
font = font?.toFont(context) ?: fallback.font,
|
|
122
|
+
toggleThumbColor = toggleThumbColor?.toColor(),
|
|
123
|
+
toggleTrackColor = toggleTrackColor?.toColor(),
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
}
|
|
@@ -7,11 +7,13 @@ import com.facebook.react.uimanager.ViewManager
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class CourierReactNativePackage : ReactPackage {
|
|
10
|
+
|
|
10
11
|
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
11
12
|
return listOf(CourierReactNativeModule(reactContext))
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
15
|
-
return listOf(
|
|
16
|
+
return listOf(CourierInboxViewManager(), CourierPreferencesViewManager())
|
|
16
17
|
}
|
|
18
|
+
|
|
17
19
|
}
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
package com.courierreactnative
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.graphics.Color
|
|
5
|
+
import android.graphics.Typeface
|
|
6
|
+
import androidx.recyclerview.widget.DividerItemDecoration
|
|
7
|
+
import com.courier.android.models.CourierPreferenceTopic
|
|
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
|
|
12
|
+
import com.courier.android.ui.CourierStyles
|
|
4
13
|
import com.facebook.react.bridge.Arguments
|
|
5
14
|
import com.facebook.react.bridge.ReactContext
|
|
15
|
+
import com.facebook.react.bridge.ReadableMap
|
|
6
16
|
import com.facebook.react.bridge.WritableArray
|
|
7
17
|
import com.facebook.react.bridge.WritableMap
|
|
8
18
|
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
@@ -35,6 +45,8 @@ internal fun CourierPreferenceTopic.toWritableMap(): WritableMap {
|
|
|
35
45
|
map.putString("status", status.value)
|
|
36
46
|
map.putString("topicId", topicId)
|
|
37
47
|
map.putString("topicName", topicName)
|
|
48
|
+
map.putString("sectionId", sectionId)
|
|
49
|
+
map.putString("sectionName", sectionName)
|
|
38
50
|
|
|
39
51
|
val actionsArray = Arguments.createArray()
|
|
40
52
|
customRouting.forEach { routing ->
|
|
@@ -151,3 +163,58 @@ internal fun List<Any>?.toWritableArray(): WritableArray {
|
|
|
151
163
|
}
|
|
152
164
|
return array
|
|
153
165
|
}
|
|
166
|
+
|
|
167
|
+
internal fun String.toDivider(context: Context): DividerItemDecoration? = if (this == "vertical") DividerItemDecoration(context, DividerItemDecoration.VERTICAL) else null
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
internal fun String.toColor(): Int = Color.parseColor(this)
|
|
171
|
+
|
|
172
|
+
internal fun String.toFont(context: Context): Typeface? {
|
|
173
|
+
return try {
|
|
174
|
+
val assetManager = context.assets
|
|
175
|
+
Typeface.createFromAsset(assetManager, this)
|
|
176
|
+
} catch (e: Exception) {
|
|
177
|
+
e.printStackTrace()
|
|
178
|
+
null
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
internal fun ReadableMap.toFont(context: Context): CourierStyles.Font {
|
|
183
|
+
|
|
184
|
+
val typeface = getString("family")
|
|
185
|
+
val size = if (isNull("size")) null else getDouble("size")
|
|
186
|
+
val color = getString("color")
|
|
187
|
+
|
|
188
|
+
return CourierStyles.Font(
|
|
189
|
+
typeface = typeface?.toFont(context),
|
|
190
|
+
color = color?.toColor(),
|
|
191
|
+
sizeInSp = size?.toInt()
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
internal fun ReadableMap.toButton(context: Context): CourierStyles.Button {
|
|
197
|
+
|
|
198
|
+
val font = getMap("font")
|
|
199
|
+
val backgroundColor = getString("backgroundColor")
|
|
200
|
+
val cornerRadius = if (isNull("cornerRadius")) null else getDouble("cornerRadius")
|
|
201
|
+
|
|
202
|
+
return CourierStyles.Button(
|
|
203
|
+
font = font?.toFont(context),
|
|
204
|
+
backgroundColor = backgroundColor?.toColor(),
|
|
205
|
+
cornerRadiusInDp = cornerRadius?.toInt()
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
internal fun ReadableMap.toInfoViewStyle(context: Context): CourierStyles.InfoViewStyle {
|
|
211
|
+
|
|
212
|
+
val font = getMap("font")
|
|
213
|
+
val button = getMap("button")
|
|
214
|
+
|
|
215
|
+
return CourierStyles.InfoViewStyle(
|
|
216
|
+
font = font?.toFont(context) ?: CourierStyles.Font(),
|
|
217
|
+
button = button?.toButton(context) ?: CourierStyles.Button()
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
}
|
|
@@ -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", "3.2.4"
|
|
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.
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import Courier_iOS
|
|
2
|
+
|
|
3
|
+
@objc(CourierInboxViewManager)
|
|
4
|
+
class CourierInboxViewManager: RCTViewManager {
|
|
5
|
+
|
|
6
|
+
override func view() -> (CourierInboxView) {
|
|
7
|
+
return CourierInboxView()
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
@objc override static func requiresMainQueueSetup() -> Bool {
|
|
11
|
+
return true
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
class CourierInboxView : UIView {
|
|
17
|
+
|
|
18
|
+
@objc var theme: NSDictionary? = [:] {
|
|
19
|
+
didSet {
|
|
20
|
+
refresh()
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@objc var onClickInboxMessageAtIndex: RCTBubblingEventBlock? = nil
|
|
25
|
+
|
|
26
|
+
@objc var onClickInboxActionForMessageAtIndex: RCTBubblingEventBlock? = nil
|
|
27
|
+
|
|
28
|
+
@objc var onScrollInbox: RCTBubblingEventBlock? = nil
|
|
29
|
+
|
|
30
|
+
private func refresh() {
|
|
31
|
+
|
|
32
|
+
UIView.setAnimationsEnabled(false)
|
|
33
|
+
|
|
34
|
+
subviews.forEach {
|
|
35
|
+
$0.removeFromSuperview()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let lightTheme = theme?["light"] as? NSDictionary
|
|
39
|
+
let darkTheme = theme?["dark"] as? NSDictionary
|
|
40
|
+
|
|
41
|
+
let courierInbox = CourierInbox(
|
|
42
|
+
lightTheme: lightTheme?.toInboxTheme() ?? .defaultLight,
|
|
43
|
+
darkTheme: darkTheme?.toInboxTheme() ?? .defaultDark,
|
|
44
|
+
didClickInboxMessageAtIndex: { [weak self] message, index in
|
|
45
|
+
self?.onClickInboxMessageAtIndex?([
|
|
46
|
+
"message" : message.toDictionary(),
|
|
47
|
+
"index" : index
|
|
48
|
+
])
|
|
49
|
+
},
|
|
50
|
+
didClickInboxActionForMessageAtIndex: { [weak self] action, message, index in
|
|
51
|
+
self?.onClickInboxActionForMessageAtIndex?([
|
|
52
|
+
"action" : action.toDictionary(),
|
|
53
|
+
"message" : message.toDictionary(),
|
|
54
|
+
"index" : index
|
|
55
|
+
])
|
|
56
|
+
},
|
|
57
|
+
didScrollInbox: { [weak self] scrollView in
|
|
58
|
+
self?.onScrollInbox?([
|
|
59
|
+
"contentOffset" : [
|
|
60
|
+
"y": scrollView.contentOffset.y,
|
|
61
|
+
"x": scrollView.contentOffset.x
|
|
62
|
+
]
|
|
63
|
+
])
|
|
64
|
+
}
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
courierInbox.translatesAutoresizingMaskIntoConstraints = false
|
|
68
|
+
addSubview(courierInbox)
|
|
69
|
+
|
|
70
|
+
NSLayoutConstraint.activate([
|
|
71
|
+
courierInbox.topAnchor.constraint(equalTo: topAnchor),
|
|
72
|
+
courierInbox.bottomAnchor.constraint(equalTo: bottomAnchor),
|
|
73
|
+
courierInbox.leadingAnchor.constraint(equalTo: leadingAnchor),
|
|
74
|
+
courierInbox.trailingAnchor.constraint(equalTo: trailingAnchor),
|
|
75
|
+
])
|
|
76
|
+
|
|
77
|
+
UIView.setAnimationsEnabled(true)
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
internal extension NSDictionary {
|
|
84
|
+
|
|
85
|
+
func toUnreadIndicatorStyle() -> CourierStyles.Inbox.UnreadIndicatorStyle {
|
|
86
|
+
|
|
87
|
+
let indicator = self["indicator"] as? String
|
|
88
|
+
let color = self["color"] as? String
|
|
89
|
+
|
|
90
|
+
var style: CourierStyles.Inbox.UnreadIndicator = .line
|
|
91
|
+
|
|
92
|
+
if (indicator == "dot") {
|
|
93
|
+
style = .dot
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return CourierStyles.Inbox.UnreadIndicatorStyle(
|
|
97
|
+
indicator: style,
|
|
98
|
+
color: color?.toColor()
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
func toTextStyle(fallback: CourierStyles.Inbox.TextStyle) -> CourierStyles.Inbox.TextStyle {
|
|
104
|
+
|
|
105
|
+
let unread = self["unread"] as? NSDictionary
|
|
106
|
+
let read = self["read"] as? NSDictionary
|
|
107
|
+
|
|
108
|
+
return CourierStyles.Inbox.TextStyle(
|
|
109
|
+
unread: unread?.toFont() ?? fallback.unread,
|
|
110
|
+
read: read?.toFont() ?? fallback.read
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
func toButtonStyle(fallback: CourierStyles.Inbox.ButtonStyle) -> CourierStyles.Inbox.ButtonStyle {
|
|
116
|
+
|
|
117
|
+
let unread = self["unread"] as? NSDictionary
|
|
118
|
+
let read = self["read"] as? NSDictionary
|
|
119
|
+
|
|
120
|
+
return CourierStyles.Inbox.ButtonStyle(
|
|
121
|
+
unread: unread?.toButton(fallback: fallback.unread) ?? fallback.unread,
|
|
122
|
+
read: read?.toButton(fallback: fallback.read) ?? fallback.read
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
func toInboxTheme() -> CourierInboxTheme? {
|
|
128
|
+
|
|
129
|
+
let defaultTheme = CourierInboxTheme()
|
|
130
|
+
|
|
131
|
+
let brandId = self["brandId"] as? String
|
|
132
|
+
let unreadIndicatorStyle = self["unreadIndicatorStyle"] as? NSDictionary
|
|
133
|
+
let loadingIndicatorColor = self["loadingIndicatorColor"] as? String
|
|
134
|
+
let titleStyle = self["titleStyle"] as? NSDictionary
|
|
135
|
+
let timeStyle = self["timeStyle"] as? NSDictionary
|
|
136
|
+
let bodyStyle = self["bodyStyle"] as? NSDictionary
|
|
137
|
+
let infoViewStyle = self["infoViewStyle"] as? NSDictionary
|
|
138
|
+
let buttonStyle = self["buttonStyle"] as? NSDictionary
|
|
139
|
+
|
|
140
|
+
let iOS = self["iOS"] as? NSDictionary
|
|
141
|
+
let messageAnimationStyle = iOS?["messageAnimationStyle"] as? String
|
|
142
|
+
let cellStyles = iOS?["cellStyles"] as? NSDictionary
|
|
143
|
+
|
|
144
|
+
return CourierInboxTheme(
|
|
145
|
+
brandId: brandId,
|
|
146
|
+
messageAnimationStyle: messageAnimationStyle?.toRowAnimation() ?? .left,
|
|
147
|
+
loadingIndicatorColor: loadingIndicatorColor?.toColor(),
|
|
148
|
+
unreadIndicatorStyle: unreadIndicatorStyle?.toUnreadIndicatorStyle() ?? defaultTheme.unreadIndicatorStyle,
|
|
149
|
+
titleStyle: titleStyle?.toTextStyle(fallback: defaultTheme.titleStyle) ?? defaultTheme.titleStyle,
|
|
150
|
+
timeStyle: timeStyle?.toTextStyle(fallback: defaultTheme.timeStyle) ?? defaultTheme.timeStyle,
|
|
151
|
+
bodyStyle: bodyStyle?.toTextStyle(fallback: defaultTheme.bodyStyle) ?? defaultTheme.bodyStyle,
|
|
152
|
+
buttonStyle: buttonStyle?.toButtonStyle(fallback: defaultTheme.buttonStyle) ?? defaultTheme.buttonStyle,
|
|
153
|
+
cellStyle: cellStyles?.toCellStyle() ?? defaultTheme.cellStyle,
|
|
154
|
+
infoViewStyle: infoViewStyle?.toInfoView(fallback: defaultTheme.infoViewStyle) ?? defaultTheme.infoViewStyle
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#import <React/RCTViewManager.h>
|
|
2
|
+
|
|
3
|
+
@interface RCT_EXTERN_MODULE(CourierPreferencesViewManager, RCTViewManager)
|
|
4
|
+
|
|
5
|
+
RCT_EXPORT_VIEW_PROPERTY(mode, NSDictionary)
|
|
6
|
+
|
|
7
|
+
RCT_EXPORT_VIEW_PROPERTY(theme, NSDictionary)
|
|
8
|
+
|
|
9
|
+
RCT_EXPORT_VIEW_PROPERTY(onPreferenceError, RCTBubblingEventBlock)
|
|
10
|
+
|
|
11
|
+
@end
|