@trycourier/courier-react-native 2.5.1 → 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/Utils.swift +70 -0
- package/lib/commonjs/index.js +38 -14
- 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 +9 -3
- 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 +9 -3
- 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/CourierReactNativeViewManager.swift +0 -302
|
@@ -15,7 +15,7 @@ type CourierInboxViewProps = {
|
|
|
15
15
|
style?: ViewStyle;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
const ComponentName = '
|
|
18
|
+
const ComponentName = 'CourierInboxView';
|
|
19
19
|
|
|
20
20
|
const LINKING_ERROR =
|
|
21
21
|
`The package '@trycourier/courier-react-native' doesn't seem to be linked. Make sure: \n\n` +
|
|
@@ -44,7 +44,7 @@ export const CourierInboxView = (props: CourierInboxViewProps) => {
|
|
|
44
44
|
onScrollInboxListener?.remove();
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
}, [])
|
|
47
|
+
}, []);
|
|
48
48
|
|
|
49
49
|
useEffect(() => {
|
|
50
50
|
|
|
@@ -54,17 +54,17 @@ export const CourierInboxView = (props: CourierInboxViewProps) => {
|
|
|
54
54
|
onClickInboxMessageAtIndexListener = DeviceEventEmitter.addListener('courierClickMessageAtIndex', onClickInboxMessageAtIndex);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
}, [props.onClickInboxMessageAtIndex])
|
|
57
|
+
}, [props.onClickInboxMessageAtIndex]);
|
|
58
58
|
|
|
59
59
|
const onClickInboxMessageAtIndex = (event: any) => {
|
|
60
60
|
|
|
61
61
|
// Parse the native event data
|
|
62
62
|
if (props.onClickInboxMessageAtIndex) {
|
|
63
63
|
|
|
64
|
-
const index = event["index"]
|
|
65
|
-
const message = event["message"] as InboxMessage
|
|
64
|
+
const index = event["index"];
|
|
65
|
+
const message = event["message"] as InboxMessage;
|
|
66
66
|
|
|
67
|
-
props.onClickInboxMessageAtIndex(message, index)
|
|
67
|
+
props.onClickInboxMessageAtIndex(message, index);
|
|
68
68
|
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -85,11 +85,11 @@ export const CourierInboxView = (props: CourierInboxViewProps) => {
|
|
|
85
85
|
// Parse the native event data
|
|
86
86
|
if (props.onClickInboxActionForMessageAtIndex) {
|
|
87
87
|
|
|
88
|
-
const index = event["index"]
|
|
89
|
-
const action = event["action"] as InboxAction
|
|
90
|
-
const message = event["message"] as InboxMessage
|
|
88
|
+
const index = event["index"];
|
|
89
|
+
const action = event["action"] as InboxAction;
|
|
90
|
+
const message = event["message"] as InboxMessage;
|
|
91
91
|
|
|
92
|
-
props.onClickInboxActionForMessageAtIndex(action, message, index)
|
|
92
|
+
props.onClickInboxActionForMessageAtIndex(action, message, index);
|
|
93
93
|
|
|
94
94
|
}
|
|
95
95
|
|
|
@@ -110,8 +110,8 @@ export const CourierInboxView = (props: CourierInboxViewProps) => {
|
|
|
110
110
|
// Parse the native event data
|
|
111
111
|
if (props.onScrollInbox) {
|
|
112
112
|
|
|
113
|
-
const contentOffset = event["contentOffset"]
|
|
114
|
-
props.onScrollInbox(contentOffset["y"], contentOffset["x"])
|
|
113
|
+
const contentOffset = event["contentOffset"];
|
|
114
|
+
props.onScrollInbox(contentOffset["y"], contentOffset["x"]);
|
|
115
115
|
|
|
116
116
|
}
|
|
117
117
|
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Platform, requireNativeComponent, UIManager, ViewStyle } from "react-native";
|
|
3
|
+
import { CourierPreferencesMode, CourierPreferencesTheme } from "src/models/CourierPreferencesTheme";
|
|
4
|
+
|
|
5
|
+
type CourierPreferencesProps = {
|
|
6
|
+
mode?: CourierPreferencesMode,
|
|
7
|
+
theme?: {
|
|
8
|
+
light?: CourierPreferencesTheme,
|
|
9
|
+
dark?: CourierPreferencesTheme
|
|
10
|
+
};
|
|
11
|
+
onPreferenceError?: (message: string) => void;
|
|
12
|
+
style?: ViewStyle;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const ComponentName = 'CourierPreferencesView';
|
|
16
|
+
|
|
17
|
+
const LINKING_ERROR =
|
|
18
|
+
`The package '@trycourier/courier-react-native' doesn't seem to be linked. Make sure: \n\n` +
|
|
19
|
+
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
20
|
+
'- You rebuilt the app after installing the package\n' +
|
|
21
|
+
'- You are not using Expo Go\n';
|
|
22
|
+
|
|
23
|
+
const CourierPreferences =
|
|
24
|
+
UIManager.getViewManagerConfig(ComponentName) != null
|
|
25
|
+
? requireNativeComponent<CourierPreferencesProps>(ComponentName)
|
|
26
|
+
: () => {
|
|
27
|
+
throw new Error(LINKING_ERROR);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const CourierPreferencesView = (props: CourierPreferencesProps) => {
|
|
31
|
+
|
|
32
|
+
const onPreferenceError = (event: any) => {
|
|
33
|
+
|
|
34
|
+
// Parse the native event data
|
|
35
|
+
if (props.onPreferenceError) {
|
|
36
|
+
|
|
37
|
+
const message = event["error"];
|
|
38
|
+
props.onPreferenceError(message);
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<CourierPreferences
|
|
46
|
+
mode={props.mode}
|
|
47
|
+
theme={props.theme ?? { light: undefined, dark: undefined }}
|
|
48
|
+
onPreferenceError={(event: any) => onPreferenceError(event.nativeEvent)}
|
|
49
|
+
style={props.style}
|
|
50
|
+
/>
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
}
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
package com.courierreactnative
|
|
2
|
-
|
|
3
|
-
import android.content.Context
|
|
4
|
-
import android.graphics.Color
|
|
5
|
-
import android.graphics.Typeface
|
|
6
|
-
import android.view.View
|
|
7
|
-
import androidx.recyclerview.widget.DividerItemDecoration
|
|
8
|
-
import com.courier.android.inbox.*
|
|
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
|
-
|
|
16
|
-
class CourierReactNativeViewManager : SimpleViewManager<CourierInbox>() {
|
|
17
|
-
|
|
18
|
-
private companion object {
|
|
19
|
-
const val ON_CLICK_MESSAGE_AT_INDEX = "courierClickMessageAtIndex"
|
|
20
|
-
const val ON_CLICK_ACTION_AT_INDEX = "courierClickActionAtIndex"
|
|
21
|
-
const val ON_SCROLL = "courierScrollInbox"
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
override fun getName() = "CourierReactNativeView"
|
|
25
|
-
|
|
26
|
-
override fun createViewInstance(reactContext: ThemedReactContext): CourierInbox = CourierInbox(reactContext)
|
|
27
|
-
|
|
28
|
-
private val View.reactContext: ThemedReactContext get() = context as ThemedReactContext
|
|
29
|
-
|
|
30
|
-
@ReactProp(name = "onClickInboxMessageAtIndex")
|
|
31
|
-
fun setOnClickInboxMessageAtIndex(view: CourierInbox, callback: Boolean) {
|
|
32
|
-
|
|
33
|
-
view.setOnClickMessageListener { message, index ->
|
|
34
|
-
|
|
35
|
-
val map = Arguments.createMap()
|
|
36
|
-
map.putMap("message", message.toWritableMap())
|
|
37
|
-
map.putInt("index", index)
|
|
38
|
-
|
|
39
|
-
view.reactContext.sendEvent(ON_CLICK_MESSAGE_AT_INDEX, map)
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
@ReactProp(name = "onClickInboxActionForMessageAtIndex")
|
|
46
|
-
fun setOnClickInboxActionForMessageAtIndex(view: CourierInbox, callback: Boolean) {
|
|
47
|
-
|
|
48
|
-
view.setOnClickActionListener { action, message, index ->
|
|
49
|
-
|
|
50
|
-
val map = Arguments.createMap()
|
|
51
|
-
map.putMap("action", action.toWritableMap())
|
|
52
|
-
map.putMap("message", message.toWritableMap())
|
|
53
|
-
map.putInt("index", index)
|
|
54
|
-
|
|
55
|
-
view.reactContext.sendEvent(ON_CLICK_ACTION_AT_INDEX, map)
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
@ReactProp(name = "onScrollInbox")
|
|
62
|
-
fun setOnScrollInbox(view: CourierInbox, callback: Boolean) {
|
|
63
|
-
|
|
64
|
-
view.setOnScrollInboxListener { offsetInDp ->
|
|
65
|
-
|
|
66
|
-
val offset = Arguments.createMap()
|
|
67
|
-
offset.putInt("y", offsetInDp)
|
|
68
|
-
offset.putInt("x", 0)
|
|
69
|
-
|
|
70
|
-
val map = Arguments.createMap()
|
|
71
|
-
map.putMap("contentOffset", offset)
|
|
72
|
-
|
|
73
|
-
view.reactContext.sendEvent(ON_SCROLL, map)
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
@ReactProp(name = "theme")
|
|
80
|
-
fun setTheme(view: CourierInbox, theme: ReadableMap) {
|
|
81
|
-
view.lightTheme = theme.getMap("light")?.toTheme(view) ?: CourierInboxTheme.DEFAULT_LIGHT
|
|
82
|
-
view.darkTheme = theme.getMap("dark")?.toTheme(view) ?: CourierInboxTheme.DEFAULT_DARK
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
private fun ReadableMap.toTheme(view: View): CourierInboxTheme {
|
|
86
|
-
|
|
87
|
-
val android = getMap("android")
|
|
88
|
-
val dividerItemDecoration = android?.getString("dividerItemDecoration")
|
|
89
|
-
|
|
90
|
-
val unreadIndicatorStyle = getMap("unreadIndicatorStyle")
|
|
91
|
-
val loadingIndicatorColor = getString("loadingIndicatorColor")
|
|
92
|
-
|
|
93
|
-
val titleStyle = getMap("titleStyle")
|
|
94
|
-
val timeStyle = getMap("timeStyle")
|
|
95
|
-
val bodyStyle = getMap("bodyStyle")
|
|
96
|
-
val infoViewStyle = getMap("infoViewStyle")
|
|
97
|
-
val buttonStyles = getMap("buttonStyles")
|
|
98
|
-
|
|
99
|
-
val context = view.context
|
|
100
|
-
|
|
101
|
-
return CourierInboxTheme(
|
|
102
|
-
unreadIndicatorStyle = unreadIndicatorStyle?.toUnreadIndicatorStyle() ?: CourierInboxUnreadIndicatorStyle(),
|
|
103
|
-
loadingIndicatorColor = loadingIndicatorColor?.toColor(),
|
|
104
|
-
titleStyle = titleStyle?.toTextStyle(context) ?: CourierInboxTextStyle(
|
|
105
|
-
unread = CourierInboxFont(),
|
|
106
|
-
read = CourierInboxFont(),
|
|
107
|
-
),
|
|
108
|
-
timeStyle = timeStyle?.toTextStyle(context) ?: CourierInboxTextStyle(
|
|
109
|
-
unread = CourierInboxFont(),
|
|
110
|
-
read = CourierInboxFont(),
|
|
111
|
-
),
|
|
112
|
-
bodyStyle = bodyStyle?.toTextStyle(context) ?: CourierInboxTextStyle(
|
|
113
|
-
unread = CourierInboxFont(),
|
|
114
|
-
read = CourierInboxFont(),
|
|
115
|
-
),
|
|
116
|
-
buttonStyle = buttonStyles?.toButtonStyle(context) ?: CourierInboxButtonStyle(
|
|
117
|
-
unread = CourierInboxButton(),
|
|
118
|
-
read = CourierInboxButton(),
|
|
119
|
-
),
|
|
120
|
-
infoViewStyle = infoViewStyle?.toInfoStyle(context) ?: CourierInboxInfoViewStyle(
|
|
121
|
-
font = CourierInboxFont(),
|
|
122
|
-
button = CourierInboxButton(),
|
|
123
|
-
),
|
|
124
|
-
dividerItemDecoration = dividerItemDecoration?.toDivider(context),
|
|
125
|
-
)
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
private fun String.toColor(): Int = Color.parseColor(this)
|
|
130
|
-
|
|
131
|
-
private fun String.toFont(context: Context): Typeface? {
|
|
132
|
-
return try {
|
|
133
|
-
val assetManager = context.assets
|
|
134
|
-
Typeface.createFromAsset(assetManager, this)
|
|
135
|
-
} catch (e: Exception) {
|
|
136
|
-
e.printStackTrace()
|
|
137
|
-
null
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
private fun String.toDivider(context: Context): DividerItemDecoration? = if (this == "vertical") DividerItemDecoration(context, DividerItemDecoration.VERTICAL) else null
|
|
142
|
-
|
|
143
|
-
private fun ReadableMap.toFont(context: Context): CourierInboxFont {
|
|
144
|
-
|
|
145
|
-
val typeface = getString("family")
|
|
146
|
-
val size = if (isNull("size")) null else getDouble("size")
|
|
147
|
-
val color = getString("color")
|
|
148
|
-
|
|
149
|
-
return CourierInboxFont(
|
|
150
|
-
typeface = typeface?.toFont(context),
|
|
151
|
-
color = color?.toColor(),
|
|
152
|
-
sizeInSp = size?.toInt()
|
|
153
|
-
)
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
private fun ReadableMap.toTextStyle(context: Context): CourierInboxTextStyle {
|
|
158
|
-
|
|
159
|
-
val unread = getMap("unread")
|
|
160
|
-
val read = getMap("read")
|
|
161
|
-
|
|
162
|
-
return CourierInboxTextStyle(
|
|
163
|
-
unread = unread?.toFont(context) ?: CourierInboxFont(),
|
|
164
|
-
read = read?.toFont(context) ?: CourierInboxFont(),
|
|
165
|
-
)
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
private fun ReadableMap.toUnreadIndicatorStyle(): CourierInboxUnreadIndicatorStyle {
|
|
170
|
-
|
|
171
|
-
val indicator = getString("indicator")
|
|
172
|
-
val color = getString("color")
|
|
173
|
-
|
|
174
|
-
var style = CourierInboxUnreadIndicator.LINE
|
|
175
|
-
|
|
176
|
-
if (indicator == "dot") {
|
|
177
|
-
style = CourierInboxUnreadIndicator.DOT
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return CourierInboxUnreadIndicatorStyle(
|
|
181
|
-
indicator = style,
|
|
182
|
-
color = color?.toColor(),
|
|
183
|
-
)
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
private fun ReadableMap.toButton(context: Context): CourierInboxButton {
|
|
188
|
-
|
|
189
|
-
val font = getMap("font")
|
|
190
|
-
val backgroundColor = getString("backgroundColor")
|
|
191
|
-
val cornerRadius = if (isNull("cornerRadius")) null else getDouble("cornerRadius")
|
|
192
|
-
|
|
193
|
-
return CourierInboxButton(
|
|
194
|
-
font = font?.toFont(context),
|
|
195
|
-
backgroundColor = backgroundColor?.toColor(),
|
|
196
|
-
cornerRadiusInDp = cornerRadius?.toInt()
|
|
197
|
-
)
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
private fun ReadableMap.toButtonStyle(context: Context): CourierInboxButtonStyle {
|
|
202
|
-
|
|
203
|
-
val unread = getMap("unread")
|
|
204
|
-
val read = getMap("read")
|
|
205
|
-
|
|
206
|
-
return CourierInboxButtonStyle(
|
|
207
|
-
unread = unread?.toButton(context) ?: CourierInboxButton(),
|
|
208
|
-
read = read?.toButton(context) ?: CourierInboxButton()
|
|
209
|
-
)
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
private fun ReadableMap.toInfoStyle(context: Context): CourierInboxInfoViewStyle {
|
|
214
|
-
|
|
215
|
-
val font = getMap("font")
|
|
216
|
-
val button = getMap("button")
|
|
217
|
-
|
|
218
|
-
return CourierInboxInfoViewStyle(
|
|
219
|
-
font = font?.toFont(context) ?: CourierInboxFont(),
|
|
220
|
-
button = button?.toButton(context) ?: CourierInboxButton()
|
|
221
|
-
)
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
}
|
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
import Courier_iOS
|
|
2
|
-
|
|
3
|
-
@objc(CourierReactNativeViewManager)
|
|
4
|
-
class CourierReactNativeViewManager: RCTViewManager {
|
|
5
|
-
|
|
6
|
-
override func view() -> (CourierReactNativeView) {
|
|
7
|
-
return CourierReactNativeView()
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
@objc override static func requiresMainQueueSetup() -> Bool {
|
|
11
|
-
return true
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
class CourierReactNativeView : UIView {
|
|
17
|
-
|
|
18
|
-
@objc var theme: NSDictionary? = [:] {
|
|
19
|
-
didSet {
|
|
20
|
-
refreshInbox()
|
|
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 refreshInbox() {
|
|
31
|
-
|
|
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
|
|
42
|
-
|
|
43
|
-
// Create the view
|
|
44
|
-
let courierInbox = CourierInbox(
|
|
45
|
-
lightTheme: dictionaryToTheme(dictionary: lightTheme) ?? .defaultLight,
|
|
46
|
-
darkTheme: dictionaryToTheme(dictionary: darkTheme) ?? .defaultDark,
|
|
47
|
-
didClickInboxMessageAtIndex: { [weak self] message, index in
|
|
48
|
-
self?.onClickInboxMessageAtIndex?([
|
|
49
|
-
"message" : message.toDictionary(),
|
|
50
|
-
"index" : index
|
|
51
|
-
])
|
|
52
|
-
},
|
|
53
|
-
didClickInboxActionForMessageAtIndex: { [weak self] action, message, index in
|
|
54
|
-
self?.onClickInboxActionForMessageAtIndex?([
|
|
55
|
-
"action" : action.toDictionary(),
|
|
56
|
-
"message" : message.toDictionary(),
|
|
57
|
-
"index" : index
|
|
58
|
-
])
|
|
59
|
-
},
|
|
60
|
-
didScrollInbox: { [weak self] scrollView in
|
|
61
|
-
self?.onScrollInbox?([
|
|
62
|
-
"contentOffset" : [
|
|
63
|
-
"y": scrollView.contentOffset.y,
|
|
64
|
-
"x": scrollView.contentOffset.x
|
|
65
|
-
]
|
|
66
|
-
])
|
|
67
|
-
}
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
// Add the view to your UI
|
|
71
|
-
courierInbox.translatesAutoresizingMaskIntoConstraints = false
|
|
72
|
-
addSubview(courierInbox)
|
|
73
|
-
|
|
74
|
-
// Constrain the view how you'd like
|
|
75
|
-
NSLayoutConstraint.activate([
|
|
76
|
-
courierInbox.topAnchor.constraint(equalTo: topAnchor),
|
|
77
|
-
courierInbox.bottomAnchor.constraint(equalTo: bottomAnchor),
|
|
78
|
-
courierInbox.leadingAnchor.constraint(equalTo: leadingAnchor),
|
|
79
|
-
courierInbox.trailingAnchor.constraint(equalTo: trailingAnchor),
|
|
80
|
-
])
|
|
81
|
-
|
|
82
|
-
// Enable animations
|
|
83
|
-
UIView.setAnimationsEnabled(true)
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
func dictionaryToTheme(dictionary: NSDictionary?) -> CourierInboxTheme? {
|
|
88
|
-
|
|
89
|
-
guard let dict = dictionary else {
|
|
90
|
-
return nil
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// iOS Theme
|
|
94
|
-
let iOS = dict["iOS"] as? [String : Any]
|
|
95
|
-
let messageAnimationStyle = iOS?["messageAnimationStyle"] as? String
|
|
96
|
-
let cellStyles = iOS?["cellStyles"] as? [String : Any]
|
|
97
|
-
|
|
98
|
-
// Unread
|
|
99
|
-
let unreadIndicatorStyle = dict["unreadIndicatorStyle"] as? [String : Any]
|
|
100
|
-
|
|
101
|
-
// Loading
|
|
102
|
-
let loadingIndicatorColor = dict["loadingIndicatorColor"] as? String
|
|
103
|
-
|
|
104
|
-
// Title
|
|
105
|
-
let titleStyle = dict["titleStyle"] as? [String : Any]
|
|
106
|
-
|
|
107
|
-
// Time
|
|
108
|
-
let timeStyle = dict["timeStyle"] as? [String : Any]
|
|
109
|
-
|
|
110
|
-
// Body
|
|
111
|
-
let bodyStyle = dict["bodyStyle"] as? [String : Any]
|
|
112
|
-
|
|
113
|
-
// Info View
|
|
114
|
-
let infoViewStyle = dict["infoViewStyle"] as? [String : Any]
|
|
115
|
-
|
|
116
|
-
// Button
|
|
117
|
-
let buttonStyle = dict["buttonStyle"] as? [String : Any]
|
|
118
|
-
|
|
119
|
-
return CourierInboxTheme(
|
|
120
|
-
messageAnimationStyle: messageAnimationStyle?.toRowAnimation() ?? .left,
|
|
121
|
-
loadingIndicatorColor: loadingIndicatorColor?.toColor(),
|
|
122
|
-
unreadIndicatorStyle: dictionaryToUnreadStyle(dictionary: unreadIndicatorStyle),
|
|
123
|
-
titleStyle: dictionaryToTextStyle(dictionary: titleStyle),
|
|
124
|
-
timeStyle: dictionaryToTextStyle(dictionary: timeStyle),
|
|
125
|
-
bodyStyle: dictionaryToTextStyle(dictionary: bodyStyle),
|
|
126
|
-
buttonStyle: dictionaryToButtonStyle(dictionary: buttonStyle),
|
|
127
|
-
cellStyle: dictionaryToCellStyles(dictionary: cellStyles),
|
|
128
|
-
infoViewStyle: dictionaryToInfoViewStyle(dictionary: infoViewStyle)
|
|
129
|
-
)
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
func dictionaryToUnreadStyle(dictionary: [String : Any]?) -> CourierInboxUnreadIndicatorStyle {
|
|
134
|
-
|
|
135
|
-
guard let dict = dictionary else {
|
|
136
|
-
return CourierInboxUnreadIndicatorStyle()
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
let indicator = dict["indicator"] as? String
|
|
140
|
-
let color = dict["color"] as? String
|
|
141
|
-
|
|
142
|
-
var style: CourierInboxUnreadIndicator = .line
|
|
143
|
-
|
|
144
|
-
if (indicator == "dot") {
|
|
145
|
-
style = .dot
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return CourierInboxUnreadIndicatorStyle(
|
|
149
|
-
indicator: style,
|
|
150
|
-
color: color?.toColor()
|
|
151
|
-
)
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
func dictionaryToFont(dictionary: [String : Any]?, defaultFont: UIFont, defaultColor: UIColor) -> CourierInboxFont {
|
|
156
|
-
|
|
157
|
-
guard let dict = dictionary else {
|
|
158
|
-
return CourierInboxFont(
|
|
159
|
-
font: defaultFont,
|
|
160
|
-
color: defaultColor
|
|
161
|
-
)
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
let family = dict["family"] as? String ?? defaultFont.familyName
|
|
165
|
-
let size = dict["size"] as? CGFloat ?? defaultFont.pointSize
|
|
166
|
-
let color = dict["color"] as? String
|
|
167
|
-
|
|
168
|
-
return CourierInboxFont(
|
|
169
|
-
font: UIFont(name: family, size: size) ?? defaultFont,
|
|
170
|
-
color: color?.toColor() ?? defaultColor
|
|
171
|
-
)
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
func dictionaryToButton(dictionary: [String : Any]?) -> CourierInboxButton {
|
|
176
|
-
|
|
177
|
-
guard let dict = dictionary else {
|
|
178
|
-
return CourierInboxButton(
|
|
179
|
-
font: CourierInboxFont(
|
|
180
|
-
font: UIFont.systemFont(ofSize: UIFont.labelFontSize),
|
|
181
|
-
color: .white
|
|
182
|
-
)
|
|
183
|
-
)
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
let font = dict["font"] as? [String : Any]
|
|
187
|
-
let backgroundColor = dict["backgroundColor"] as? String
|
|
188
|
-
let cornerRadius = dict["cornerRadius"] as? CGFloat
|
|
189
|
-
|
|
190
|
-
return CourierInboxButton(
|
|
191
|
-
font: dictionaryToFont(
|
|
192
|
-
dictionary: font,
|
|
193
|
-
defaultFont: UIFont.systemFont(ofSize: UIFont.labelFontSize),
|
|
194
|
-
defaultColor: .white
|
|
195
|
-
),
|
|
196
|
-
backgroundColor: backgroundColor?.toColor(),
|
|
197
|
-
cornerRadius: cornerRadius ?? 8
|
|
198
|
-
)
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
func dictionaryToButtonStyle(dictionary: [String : Any]?) -> CourierInboxButtonStyle {
|
|
203
|
-
|
|
204
|
-
guard let dict = dictionary else {
|
|
205
|
-
return CourierInboxButtonStyle()
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
let unread = dict["unread"] as? [String : Any]
|
|
209
|
-
let read = dict["read"] as? [String : Any]
|
|
210
|
-
|
|
211
|
-
return CourierInboxButtonStyle(
|
|
212
|
-
unread: dictionaryToButton(dictionary: unread),
|
|
213
|
-
read: dictionaryToButton(dictionary: read)
|
|
214
|
-
)
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
func dictionaryToInfoViewStyle(dictionary: [String : Any]?) -> CourierInboxInfoViewStyle {
|
|
219
|
-
|
|
220
|
-
let defaultColor: UIColor = .label
|
|
221
|
-
let defaultFont: UIFont = UIFont.systemFont(ofSize: UIFont.labelFontSize)
|
|
222
|
-
|
|
223
|
-
let defaultInboxFont = CourierInboxFont(
|
|
224
|
-
font: defaultFont,
|
|
225
|
-
color: defaultColor
|
|
226
|
-
)
|
|
227
|
-
|
|
228
|
-
guard let dict = dictionary else {
|
|
229
|
-
return CourierInboxInfoViewStyle(
|
|
230
|
-
font: defaultInboxFont,
|
|
231
|
-
button: CourierInboxButton(
|
|
232
|
-
font: defaultInboxFont
|
|
233
|
-
)
|
|
234
|
-
)
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
let font = dict["font"] as? [String : Any]
|
|
238
|
-
let button = dict["button"] as? [String : Any]
|
|
239
|
-
|
|
240
|
-
return CourierInboxInfoViewStyle(
|
|
241
|
-
font: dictionaryToFont(dictionary: font, defaultFont: defaultFont, defaultColor: defaultColor),
|
|
242
|
-
button: dictionaryToButton(dictionary: button)
|
|
243
|
-
)
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
func dictionaryToTextStyle(dictionary: [String : Any]?) -> CourierInboxTextStyle {
|
|
248
|
-
|
|
249
|
-
let defaultColor: UIColor = .label
|
|
250
|
-
let defaultFont: UIFont = UIFont.systemFont(ofSize: UIFont.labelFontSize)
|
|
251
|
-
|
|
252
|
-
let defaultInboxFont = CourierInboxFont(
|
|
253
|
-
font: defaultFont,
|
|
254
|
-
color: defaultColor
|
|
255
|
-
)
|
|
256
|
-
|
|
257
|
-
let defaultText = CourierInboxTextStyle(
|
|
258
|
-
unread: defaultInboxFont,
|
|
259
|
-
read: defaultInboxFont
|
|
260
|
-
)
|
|
261
|
-
|
|
262
|
-
guard let dict = dictionary else {
|
|
263
|
-
return defaultText
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
let unread = dict["unread"] as? [String : Any]
|
|
267
|
-
let read = dict["read"] as? [String : Any]
|
|
268
|
-
|
|
269
|
-
return CourierInboxTextStyle(
|
|
270
|
-
unread: dictionaryToFont(dictionary: unread, defaultFont: defaultFont, defaultColor: defaultColor),
|
|
271
|
-
read: dictionaryToFont(dictionary: read, defaultFont: defaultFont, defaultColor: defaultColor)
|
|
272
|
-
)
|
|
273
|
-
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
func dictionaryToCellStyles(dictionary: [String : Any]?) -> CourierInboxCellStyle {
|
|
277
|
-
|
|
278
|
-
guard let dict = dictionary else {
|
|
279
|
-
return CourierInboxCellStyle()
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
let separatorStyle = dict["separatorStyle"] as? String
|
|
283
|
-
let separatorColor = dict["separatorColor"] as? String
|
|
284
|
-
let selectionStyle = dict["selectionStyle"] as? String
|
|
285
|
-
|
|
286
|
-
let insets = dict["separatorInsets"] as? [String : Any]
|
|
287
|
-
let top = insets?["top"] as? CGFloat
|
|
288
|
-
let left = insets?["left"] as? CGFloat
|
|
289
|
-
let right = insets?["right"] as? CGFloat
|
|
290
|
-
let bottom = insets?["bottom"] as? CGFloat
|
|
291
|
-
let separatorInsets = UIEdgeInsets(top: top ?? 0, left: left ?? 0, bottom: bottom ?? 0, right: right ?? 0)
|
|
292
|
-
|
|
293
|
-
return CourierInboxCellStyle(
|
|
294
|
-
separatorStyle: separatorStyle?.toSeparatorStyle() ?? .singleLine,
|
|
295
|
-
separatorInsets: separatorInsets,
|
|
296
|
-
separatorColor: separatorColor?.toColor(),
|
|
297
|
-
selectionStyle: selectionStyle?.toSelectionStyle() ?? .default
|
|
298
|
-
)
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
}
|