@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.
Files changed (93) hide show
  1. package/android/build.gradle +1 -1
  2. package/android/src/main/java/com/courierreactnative/CourierInboxViewManager.kt +187 -0
  3. package/android/src/main/java/com/courierreactnative/CourierPreferencesViewManager.kt +128 -0
  4. package/android/src/main/java/com/courierreactnative/CourierReactNativePackage.kt +3 -1
  5. package/android/src/main/java/com/courierreactnative/Extensions.kt +68 -1
  6. package/courier-react-native.podspec +1 -1
  7. package/ios/{CourierReactNativeViewManager.m → CourierInboxReactNativeManager.m} +1 -1
  8. package/ios/CourierInboxReactNativeManager.swift +159 -0
  9. package/ios/CourierPreferencesReactNativeManager.m +11 -0
  10. package/ios/CourierPreferencesReactNativeManager.swift +140 -0
  11. package/ios/CourierReactNativeModule.swift +50 -36
  12. package/ios/Utils.swift +70 -0
  13. package/lib/commonjs/index.js +54 -36
  14. package/lib/commonjs/index.js.map +1 -1
  15. package/lib/commonjs/models/Android_CourierSheet.js +6 -0
  16. package/lib/commonjs/models/Android_CourierSheet.js.map +1 -0
  17. package/lib/commonjs/models/CourierButton.js +6 -0
  18. package/lib/commonjs/models/CourierButton.js.map +1 -0
  19. package/lib/commonjs/models/CourierFont.js +2 -0
  20. package/lib/commonjs/models/CourierFont.js.map +1 -0
  21. package/lib/commonjs/models/CourierInboxTheme.js +4 -0
  22. package/lib/commonjs/models/CourierInfoViewStyle.js +6 -0
  23. package/lib/commonjs/models/CourierInfoViewStyle.js.map +1 -0
  24. package/lib/commonjs/models/CourierPreferencesTheme.js +6 -0
  25. package/lib/commonjs/models/CourierPreferencesTheme.js.map +1 -0
  26. package/lib/commonjs/models/iOS_CourierCell.js +2 -0
  27. package/lib/commonjs/models/iOS_CourierCell.js.map +1 -0
  28. package/lib/commonjs/models/iOS_CourierSheet.js +6 -0
  29. package/lib/commonjs/models/iOS_CourierSheet.js.map +1 -0
  30. package/lib/commonjs/views/CourierInboxView.js +1 -1
  31. package/lib/commonjs/views/CourierInboxView.js.map +1 -1
  32. package/lib/commonjs/views/CourierPreferencesView.js +37 -0
  33. package/lib/commonjs/views/CourierPreferencesView.js.map +1 -0
  34. package/lib/module/index.js +25 -25
  35. package/lib/module/index.js.map +1 -1
  36. package/lib/module/models/Android_CourierSheet.js +2 -0
  37. package/lib/module/models/Android_CourierSheet.js.map +1 -0
  38. package/lib/module/models/CourierButton.js +2 -0
  39. package/lib/module/models/CourierButton.js.map +1 -0
  40. package/lib/module/models/CourierFont.js +2 -0
  41. package/lib/module/models/CourierFont.js.map +1 -0
  42. package/lib/module/models/CourierInboxTheme.js +1 -1
  43. package/lib/module/models/CourierInfoViewStyle.js +2 -0
  44. package/lib/module/models/CourierInfoViewStyle.js.map +1 -0
  45. package/lib/module/models/CourierPreferencesTheme.js +2 -0
  46. package/lib/module/models/CourierPreferencesTheme.js.map +1 -0
  47. package/lib/module/models/iOS_CourierCell.js +2 -0
  48. package/lib/module/models/iOS_CourierCell.js.map +1 -0
  49. package/lib/module/models/iOS_CourierSheet.js +2 -0
  50. package/lib/module/models/iOS_CourierSheet.js.map +1 -0
  51. package/lib/module/views/CourierInboxView.js +1 -1
  52. package/lib/module/views/CourierInboxView.js.map +1 -1
  53. package/lib/module/views/CourierPreferencesView.js +29 -0
  54. package/lib/module/views/CourierPreferencesView.js.map +1 -0
  55. package/lib/typescript/index.d.ts +9 -3
  56. package/lib/typescript/index.d.ts.map +1 -1
  57. package/lib/typescript/models/Android_CourierSheet.d.ts +7 -0
  58. package/lib/typescript/models/Android_CourierSheet.d.ts.map +1 -0
  59. package/lib/typescript/models/CourierButton.d.ts +7 -0
  60. package/lib/typescript/models/CourierButton.d.ts.map +1 -0
  61. package/lib/typescript/models/CourierFont.d.ts +6 -0
  62. package/lib/typescript/models/CourierFont.d.ts.map +1 -0
  63. package/lib/typescript/models/CourierInboxTheme.d.ts +9 -19
  64. package/lib/typescript/models/CourierInboxTheme.d.ts.map +1 -1
  65. package/lib/typescript/models/CourierInfoViewStyle.d.ts +7 -0
  66. package/lib/typescript/models/CourierInfoViewStyle.d.ts.map +1 -0
  67. package/lib/typescript/models/CourierPreferencesTheme.d.ts +35 -0
  68. package/lib/typescript/models/CourierPreferencesTheme.d.ts.map +1 -0
  69. package/lib/typescript/models/CourierUserPreferencesTopic.d.ts +3 -1
  70. package/lib/typescript/models/CourierUserPreferencesTopic.d.ts.map +1 -1
  71. package/lib/typescript/models/iOS_CourierCell.d.ts +12 -0
  72. package/lib/typescript/models/iOS_CourierCell.d.ts.map +1 -0
  73. package/lib/typescript/models/iOS_CourierSheet.d.ts +6 -0
  74. package/lib/typescript/models/iOS_CourierSheet.d.ts.map +1 -0
  75. package/lib/typescript/views/CourierPreferencesView.d.ts +15 -0
  76. package/lib/typescript/views/CourierPreferencesView.d.ts.map +1 -0
  77. package/package.json +5 -2
  78. package/src/index.tsx +27 -27
  79. package/src/models/Android_CourierSheet.tsx +7 -0
  80. package/src/models/CourierButton.tsx +7 -0
  81. package/src/models/CourierFont.tsx +5 -0
  82. package/src/models/CourierInboxTheme.tsx +9 -21
  83. package/src/models/CourierInfoViewStyle.tsx +7 -0
  84. package/src/models/CourierPreferencesTheme.tsx +34 -0
  85. package/src/models/CourierUserPreferencesTopic.tsx +3 -1
  86. package/src/models/iOS_CourierCell.tsx +6 -0
  87. package/src/models/iOS_CourierSheet.tsx +6 -0
  88. package/src/views/CourierInboxView.tsx +12 -12
  89. package/src/views/CourierPreferencesView.tsx +53 -0
  90. package/android/src/main/java/com/courierreactnative/CourierReactNativeViewManager.kt +0 -225
  91. package/ios/CourierAuthenticationListenerWrapper.swift +0 -14
  92. package/ios/CourierInboxListenerWrapper.swift +0 -24
  93. package/ios/CourierReactNativeViewManager.swift +0 -302
@@ -1,14 +0,0 @@
1
- //
2
- // CourierAuthenticationListenerWrapper.swift
3
- // courier-react-native
4
- //
5
- // Created by Michael Miller on 2/15/24.
6
- //
7
-
8
- import Foundation
9
- import Courier_iOS
10
-
11
- internal struct CourierAuthenticationListenerWrapper {
12
- let authId: String
13
- let listener: CourierAuthenticationListener
14
- }
@@ -1,24 +0,0 @@
1
- //
2
- // CourierInboxListenerWrapper.swift
3
- // courier-react-native
4
- //
5
- // Created by Michael Miller on 2/15/24.
6
- //
7
-
8
- import Foundation
9
- import Courier_iOS
10
-
11
- internal struct CourierInboxListenerWrapper {
12
- let loadingId: String
13
- let errorId: String
14
- let messagesId: String
15
- let listener: CourierInboxListener
16
- }
17
-
18
- extension CourierInboxListenerWrapper {
19
-
20
- internal func getIds() -> [String] {
21
- return [loadingId, errorId, messagesId]
22
- }
23
-
24
- }
@@ -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
- }