@trycourier/courier-react-native 2.0.3 → 2.2.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 (78) hide show
  1. package/README.md +13 -0
  2. package/android/build.gradle +2 -2
  3. package/android/src/main/java/com/courierreactnative/CourierReactNativeActivity.kt +0 -3
  4. package/android/src/main/java/com/courierreactnative/CourierReactNativeModule.kt +101 -22
  5. package/android/src/main/java/com/courierreactnative/CourierReactNativeViewManager.kt +84 -18
  6. package/android/src/main/java/com/courierreactnative/Extensions.kt +51 -3
  7. package/courier-react-native.podspec +1 -1
  8. package/ios/CourierReactNative.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  9. package/ios/CourierReactNative.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  10. package/ios/CourierReactNative.xcodeproj/project.xcworkspace/xcuserdata/mike.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  11. package/ios/CourierReactNative.xcodeproj/xcuserdata/mike.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  12. package/ios/CourierReactNativeModule.m +32 -9
  13. package/ios/CourierReactNativeModule.swift +59 -26
  14. package/ios/CourierReactNativeViewManager.swift +117 -159
  15. package/ios/Utils.swift +199 -0
  16. package/lib/commonjs/index.js +83 -28
  17. package/lib/commonjs/index.js.map +1 -1
  18. package/lib/commonjs/models/CourierPaging.js +2 -0
  19. package/lib/commonjs/models/CourierPaging.js.map +1 -0
  20. package/lib/commonjs/models/CourierPushProvider.js +16 -0
  21. package/lib/commonjs/models/CourierPushProvider.js.map +1 -0
  22. package/lib/commonjs/models/CourierUserPreferences.js +6 -0
  23. package/lib/commonjs/models/CourierUserPreferences.js.map +1 -0
  24. package/lib/commonjs/models/CourierUserPreferencesChannel.js +17 -0
  25. package/lib/commonjs/models/CourierUserPreferencesChannel.js.map +1 -0
  26. package/lib/commonjs/models/CourierUserPreferencesStatus.js +15 -0
  27. package/lib/commonjs/models/CourierUserPreferencesStatus.js.map +1 -0
  28. package/lib/commonjs/models/CourierUserPreferencesTopic.js +6 -0
  29. package/lib/commonjs/models/CourierUserPreferencesTopic.js.map +1 -0
  30. package/lib/module/index.js +36 -17
  31. package/lib/module/index.js.map +1 -1
  32. package/lib/module/models/CourierPaging.js +2 -0
  33. package/lib/module/models/CourierPaging.js.map +1 -0
  34. package/lib/module/models/CourierPushProvider.js +9 -0
  35. package/lib/module/models/CourierPushProvider.js.map +1 -0
  36. package/lib/module/models/CourierUserPreferences.js +2 -0
  37. package/lib/module/models/CourierUserPreferences.js.map +1 -0
  38. package/lib/module/models/CourierUserPreferencesChannel.js +10 -0
  39. package/lib/module/models/CourierUserPreferencesChannel.js.map +1 -0
  40. package/lib/module/models/CourierUserPreferencesStatus.js +8 -0
  41. package/lib/module/models/CourierUserPreferencesStatus.js.map +1 -0
  42. package/lib/module/models/CourierUserPreferencesTopic.js +2 -0
  43. package/lib/module/models/CourierUserPreferencesTopic.js.map +1 -0
  44. package/lib/typescript/index.d.ts +43 -8
  45. package/lib/typescript/index.d.ts.map +1 -1
  46. package/lib/typescript/models/CourierInboxTheme.d.ts +24 -8
  47. package/lib/typescript/models/CourierInboxTheme.d.ts.map +1 -1
  48. package/lib/typescript/models/CourierPaging.d.ts +5 -0
  49. package/lib/typescript/models/CourierPaging.d.ts.map +1 -0
  50. package/lib/typescript/models/CourierPushProvider.d.ts +8 -0
  51. package/lib/typescript/models/CourierPushProvider.d.ts.map +1 -0
  52. package/lib/typescript/models/CourierUserPreferences.d.ts +7 -0
  53. package/lib/typescript/models/CourierUserPreferences.d.ts.map +1 -0
  54. package/lib/typescript/models/CourierUserPreferencesChannel.d.ts +9 -0
  55. package/lib/typescript/models/CourierUserPreferencesChannel.d.ts.map +1 -0
  56. package/lib/typescript/models/CourierUserPreferencesStatus.d.ts +7 -0
  57. package/lib/typescript/models/CourierUserPreferencesStatus.d.ts.map +1 -0
  58. package/lib/typescript/models/CourierUserPreferencesTopic.d.ts +11 -0
  59. package/lib/typescript/models/CourierUserPreferencesTopic.d.ts.map +1 -0
  60. package/lib/typescript/views/CourierInboxView.d.ts +3 -3
  61. package/lib/typescript/views/CourierInboxView.d.ts.map +1 -1
  62. package/package.json +4 -2
  63. package/src/index.tsx +43 -20
  64. package/src/models/CourierInboxTheme.tsx +28 -8
  65. package/src/models/CourierPaging.tsx +4 -0
  66. package/src/models/CourierPushProvider.tsx +7 -0
  67. package/src/models/CourierUserPreferences.tsx +7 -0
  68. package/src/models/CourierUserPreferencesChannel.tsx +8 -0
  69. package/src/models/CourierUserPreferencesStatus.tsx +6 -0
  70. package/src/models/CourierUserPreferencesTopic.tsx +11 -0
  71. package/src/views/CourierInboxView.tsx +3 -3
  72. package/lib/commonjs/hooks/CourierProvider.js +0 -254
  73. package/lib/commonjs/hooks/CourierProvider.js.map +0 -1
  74. package/lib/module/hooks/CourierProvider.js +0 -241
  75. package/lib/module/hooks/CourierProvider.js.map +0 -1
  76. package/lib/typescript/hooks/CourierProvider.d.ts +0 -57
  77. package/lib/typescript/hooks/CourierProvider.d.ts.map +0 -1
  78. package/src/hooks/CourierProvider.tsx +0 -356
@@ -96,56 +96,58 @@ class CourierReactNativeView : UIView {
96
96
  let cellStyles = iOS?["cellStyles"] as? [String : Any]
97
97
 
98
98
  // Unread
99
- let unreadIndicatorBarColor = dict["unreadIndicatorBarColor"] as? String
99
+ let unreadIndicatorStyle = dict["unreadIndicatorStyle"] as? [String : Any]
100
100
 
101
101
  // Loading
102
102
  let loadingIndicatorColor = dict["loadingIndicatorColor"] as? String
103
103
 
104
104
  // Title
105
- let titleFont = dict["titleFont"] as? [String : Any]
105
+ let titleStyle = dict["titleStyle"] as? [String : Any]
106
106
 
107
107
  // Time
108
- let timeFont = dict["timeFont"] as? [String : Any]
108
+ let timeStyle = dict["timeStyle"] as? [String : Any]
109
109
 
110
110
  // Body
111
- let bodyFont = dict["bodyFont"] as? [String : Any]
111
+ let bodyStyle = dict["bodyStyle"] as? [String : Any]
112
112
 
113
- // Detail
114
- let detailTitleFont = dict["detailTitleFont"] as? [String : Any]
113
+ // Info View
114
+ let infoViewStyle = dict["infoViewStyle"] as? [String : Any]
115
115
 
116
- // Detail
117
- let buttonStyles = dict["buttonStyles"] as? [String : Any]
116
+ // Button
117
+ let buttonStyle = dict["buttonStyle"] as? [String : Any]
118
118
 
119
119
  return CourierInboxTheme(
120
120
  messageAnimationStyle: messageAnimationStyle?.toRowAnimation() ?? .left,
121
- unreadIndicatorBarColor: unreadIndicatorBarColor?.toColor(),
122
121
  loadingIndicatorColor: loadingIndicatorColor?.toColor(),
123
- titleFont: dictionaryToFont(
124
- dictionary: titleFont,
125
- defaultFont: UIFont.boldSystemFont(ofSize: UIFont.labelFontSize),
126
- defaultColor: .label
127
- ),
128
- timeFont: dictionaryToFont(
129
- dictionary: timeFont,
130
- defaultFont: UIFont.systemFont(ofSize: UIFont.labelFontSize),
131
- defaultColor: .placeholderText
132
- ),
133
- bodyFont: dictionaryToFont(
134
- dictionary: bodyFont,
135
- defaultFont: UIFont.systemFont(ofSize: UIFont.labelFontSize),
136
- defaultColor: .label
137
- ),
138
- detailTitleFont: dictionaryToFont(
139
- dictionary: detailTitleFont,
140
- defaultFont: UIFont.systemFont(ofSize: UIFont.labelFontSize),
141
- defaultColor: .label
142
- ),
143
- buttonStyles: dictionaryToButtonStyles(
144
- dictionary: buttonStyles
145
- ),
146
- cellStyles: dictionaryToCellStyles(
147
- dictionary: cellStyles
148
- )
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()
149
151
  )
150
152
 
151
153
  }
@@ -170,17 +172,22 @@ class CourierReactNativeView : UIView {
170
172
 
171
173
  }
172
174
 
173
- func dictionaryToButtonStyles(dictionary: [String : Any]?) -> CourierInboxButtonStyles {
175
+ func dictionaryToButton(dictionary: [String : Any]?) -> CourierInboxButton {
174
176
 
175
177
  guard let dict = dictionary else {
176
- return CourierInboxButtonStyles()
178
+ return CourierInboxButton(
179
+ font: CourierInboxFont(
180
+ font: UIFont.systemFont(ofSize: UIFont.labelFontSize),
181
+ color: .white
182
+ )
183
+ )
177
184
  }
178
185
 
179
186
  let font = dict["font"] as? [String : Any]
180
187
  let backgroundColor = dict["backgroundColor"] as? String
181
188
  let cornerRadius = dict["cornerRadius"] as? CGFloat
182
189
 
183
- return CourierInboxButtonStyles(
190
+ return CourierInboxButton(
184
191
  font: dictionaryToFont(
185
192
  dictionary: font,
186
193
  defaultFont: UIFont.systemFont(ofSize: UIFont.labelFontSize),
@@ -192,151 +199,102 @@ class CourierReactNativeView : UIView {
192
199
 
193
200
  }
194
201
 
195
- func dictionaryToCellStyles(dictionary: [String : Any]?) -> CourierInboxCellStyles {
202
+ func dictionaryToButtonStyle(dictionary: [String : Any]?) -> CourierInboxButtonStyle {
196
203
 
197
204
  guard let dict = dictionary else {
198
- return CourierInboxCellStyles()
205
+ return CourierInboxButtonStyle()
199
206
  }
200
207
 
201
- let separatorStyle = dict["separatorStyle"] as? String
202
- let separatorColor = dict["separatorColor"] as? String
203
- let selectionStyle = dict["selectionStyle"] as? String
204
-
205
- let insets = dict["separatorInsets"] as? [String : Any]
206
- let top = insets?["top"] as? CGFloat
207
- let left = insets?["left"] as? CGFloat
208
- let right = insets?["right"] as? CGFloat
209
- let bottom = insets?["bottom"] as? CGFloat
210
- let separatorInsets = UIEdgeInsets(top: top ?? 0, left: left ?? 0, bottom: bottom ?? 0, right: right ?? 0)
208
+ let unread = dict["unread"] as? [String : Any]
209
+ let read = dict["read"] as? [String : Any]
211
210
 
212
- return CourierInboxCellStyles(
213
- separatorStyle: separatorStyle?.toSeparatorStyle() ?? .singleLine,
214
- separatorInsets: separatorInsets,
215
- separatorColor: separatorColor?.toColor(),
216
- selectionStyle: selectionStyle?.toSelectionStyle() ?? .default
211
+ return CourierInboxButtonStyle(
212
+ unread: dictionaryToButton(dictionary: unread),
213
+ read: dictionaryToButton(dictionary: read)
217
214
  )
218
215
 
219
216
  }
220
217
 
221
- }
222
-
223
- internal extension InboxMessage {
224
-
225
- @objc func toDictionary() -> NSDictionary {
226
-
227
- let dictionary: [String: Any?] = [
228
- "messageId": messageId,
229
- "title": title,
230
- "body": body,
231
- "preview": preview,
232
- "created": created,
233
- "actions": actions?.map { $0.toDictionary() },
234
- "data": data,
235
- "read": isRead,
236
- "opened": isOpened,
237
- "archived": isArchived
238
- ]
239
-
240
- let mutableDictionary = NSMutableDictionary()
241
- for (key, value) in dictionary {
242
- if let unwrappedValue = value {
243
- mutableDictionary[key] = unwrappedValue
244
- }
245
- }
246
-
247
- return mutableDictionary
218
+ func dictionaryToInfoViewStyle(dictionary: [String : Any]?) -> CourierInboxInfoViewStyle {
248
219
 
249
- }
250
-
251
- }
252
-
253
- internal extension InboxAction {
254
-
255
- @objc func toDictionary() -> NSDictionary {
220
+ let defaultColor: UIColor = .label
221
+ let defaultFont: UIFont = UIFont.systemFont(ofSize: UIFont.labelFontSize)
256
222
 
257
- let dictionary: [String: Any?] = [
258
- "content": content,
259
- "href": href,
260
- "data": data
261
- ]
262
-
263
- let mutableDictionary = NSMutableDictionary()
264
- for (key, value) in dictionary {
265
- if let unwrappedValue = value {
266
- mutableDictionary[key] = unwrappedValue
267
- }
268
- }
269
-
270
- return mutableDictionary
223
+ let defaultInboxFont = CourierInboxFont(
224
+ font: defaultFont,
225
+ color: defaultColor
226
+ )
271
227
 
272
- }
273
-
274
- }
275
-
276
- internal extension String {
277
-
278
- func toRowAnimation() -> UITableView.RowAnimation {
279
-
280
- switch self.lowercased() {
281
- case "fade": return .fade
282
- case "right": return .right
283
- case "left": return .left
284
- case "top": return .top
285
- case "bottom": return .bottom
286
- case "none": return .none
287
- case "middle": return .middle
288
- case "automatic":
289
- if #available(iOS 11.0, *) {
290
- return .automatic
291
- } else {
292
- return .fade
293
- }
294
- default: return .fade
228
+ guard let dict = dictionary else {
229
+ return CourierInboxInfoViewStyle(
230
+ font: defaultInboxFont,
231
+ button: CourierInboxButton(
232
+ font: defaultInboxFont
233
+ )
234
+ )
295
235
  }
296
236
 
297
- }
298
-
299
- func toSeparatorStyle() -> UITableViewCell.SeparatorStyle {
237
+ let font = dict["font"] as? [String : Any]
238
+ let button = dict["button"] as? [String : Any]
300
239
 
301
- switch self.lowercased() {
302
- case "none": return .none
303
- case "singleLine": return .singleLine
304
- case "singleLineEtched": return .singleLineEtched
305
- default: return .singleLine
306
- }
240
+ return CourierInboxInfoViewStyle(
241
+ font: dictionaryToFont(dictionary: font, defaultFont: defaultFont, defaultColor: defaultColor),
242
+ button: dictionaryToButton(dictionary: button)
243
+ )
307
244
 
308
245
  }
309
246
 
310
- func toSelectionStyle() -> UITableViewCell.SelectionStyle? {
311
-
312
- switch self.lowercased() {
313
- case "none": return .none
314
- case "blue": return .blue
315
- case "gray": return .gray
316
- case "default": return .default
317
- default: return .default
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
318
264
  }
319
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
+
320
274
  }
321
275
 
322
- func toColor() -> UIColor? {
276
+ func dictionaryToCellStyles(dictionary: [String : Any]?) -> CourierInboxCellStyle {
323
277
 
324
- var hexSanitized = trimmingCharacters(in: .whitespacesAndNewlines)
325
- hexSanitized = hexSanitized.replacingOccurrences(of: "#", with: "")
326
-
327
- var rgb: UInt64 = 0
328
-
329
- Scanner(string: hexSanitized).scanHexInt64(&rgb)
330
-
331
- guard hexSanitized.count == 6 else {
332
- return nil
278
+ guard let dict = dictionary else {
279
+ return CourierInboxCellStyle()
333
280
  }
334
-
335
- return UIColor(
336
- red: CGFloat((rgb & 0xFF0000) >> 16) / 255.0,
337
- green: CGFloat((rgb & 0x00FF00) >> 8) / 255.0,
338
- blue: CGFloat(rgb & 0x0000FF) / 255.0,
339
- alpha: 1.0
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
340
298
  )
341
299
 
342
300
  }
@@ -0,0 +1,199 @@
1
+ //
2
+ // Utils.swift
3
+ // courier-react-native
4
+ //
5
+ // Created by Michael Miller on 10/23/23.
6
+ //
7
+
8
+ import Foundation
9
+ import Courier_iOS
10
+
11
+ extension UNAuthorizationStatus {
12
+
13
+ var name: String {
14
+ switch (self) {
15
+ case .notDetermined: return "notDetermined"
16
+ case .denied: return "denied"
17
+ case .authorized: return "authorized"
18
+ case .provisional: return "provisional"
19
+ case .ephemeral: return "ephemeral"
20
+ @unknown default: return "unknown"
21
+ }
22
+ }
23
+
24
+ }
25
+
26
+ internal extension [String: Any?] {
27
+
28
+ func clean() -> NSMutableDictionary {
29
+
30
+ let mutableDictionary = NSMutableDictionary()
31
+ for (key, value) in self {
32
+ if let unwrappedValue = value {
33
+ mutableDictionary[key] = unwrappedValue
34
+ }
35
+ }
36
+
37
+ return mutableDictionary
38
+
39
+ }
40
+
41
+ }
42
+
43
+ internal extension CourierUserPreferences {
44
+
45
+ @objc func toDictionary() -> NSDictionary {
46
+
47
+ let dictionary: [String: Any?] = [
48
+ "items": items.map { $0.toDictionary() },
49
+ "paging": paging.toDictionary(),
50
+ ]
51
+
52
+ return dictionary.clean()
53
+
54
+ }
55
+
56
+ }
57
+
58
+ internal extension CourierUserPreferencesTopic {
59
+
60
+ @objc func toDictionary() -> NSDictionary {
61
+
62
+ let dictionary: [String: Any?] = [
63
+ "defaultStatus": defaultStatus.rawValue,
64
+ "hasCustomRouting": hasCustomRouting,
65
+ "customRouting": customRouting.map { $0.rawValue },
66
+ "status": status,
67
+ "topicId": topicId,
68
+ "topicName": topicName,
69
+ ]
70
+
71
+ return dictionary.clean()
72
+
73
+ }
74
+
75
+ }
76
+
77
+ internal extension CourierUserPreferencesPaging {
78
+
79
+ @objc func toDictionary() -> NSDictionary {
80
+
81
+ let dictionary: [String: Any?] = [
82
+ "cursor": cursor,
83
+ "more": more,
84
+ ]
85
+
86
+ return dictionary.clean()
87
+
88
+ }
89
+
90
+ }
91
+
92
+ internal extension InboxMessage {
93
+
94
+ @objc func toDictionary() -> NSDictionary {
95
+
96
+ let dictionary: [String: Any?] = [
97
+ "messageId": messageId,
98
+ "title": title,
99
+ "body": body,
100
+ "preview": preview,
101
+ "created": created,
102
+ "actions": actions?.map { $0.toDictionary() },
103
+ "data": data,
104
+ "read": isRead,
105
+ "opened": isOpened,
106
+ "archived": isArchived
107
+ ]
108
+
109
+ return dictionary.clean()
110
+
111
+ }
112
+
113
+ }
114
+
115
+ internal extension InboxAction {
116
+
117
+ @objc func toDictionary() -> NSDictionary {
118
+
119
+ let dictionary: [String: Any?] = [
120
+ "content": content,
121
+ "href": href,
122
+ "data": data
123
+ ]
124
+
125
+ return dictionary.clean()
126
+
127
+ }
128
+
129
+ }
130
+
131
+ internal extension String {
132
+
133
+ func toRowAnimation() -> UITableView.RowAnimation {
134
+
135
+ switch self.lowercased() {
136
+ case "fade": return .fade
137
+ case "right": return .right
138
+ case "left": return .left
139
+ case "top": return .top
140
+ case "bottom": return .bottom
141
+ case "none": return .none
142
+ case "middle": return .middle
143
+ case "automatic":
144
+ if #available(iOS 11.0, *) {
145
+ return .automatic
146
+ } else {
147
+ return .fade
148
+ }
149
+ default: return .fade
150
+ }
151
+
152
+ }
153
+
154
+ func toSeparatorStyle() -> UITableViewCell.SeparatorStyle {
155
+
156
+ switch self.lowercased() {
157
+ case "none": return .none
158
+ case "singleLine": return .singleLine
159
+ case "singleLineEtched": return .singleLineEtched
160
+ default: return .singleLine
161
+ }
162
+
163
+ }
164
+
165
+ func toSelectionStyle() -> UITableViewCell.SelectionStyle? {
166
+
167
+ switch self.lowercased() {
168
+ case "none": return .none
169
+ case "blue": return .blue
170
+ case "gray": return .gray
171
+ case "default": return .default
172
+ default: return .default
173
+ }
174
+
175
+ }
176
+
177
+ func toColor() -> UIColor? {
178
+
179
+ var hexSanitized = trimmingCharacters(in: .whitespacesAndNewlines)
180
+ hexSanitized = hexSanitized.replacingOccurrences(of: "#", with: "")
181
+
182
+ var rgb: UInt64 = 0
183
+
184
+ Scanner(string: hexSanitized).scanHexInt64(&rgb)
185
+
186
+ guard hexSanitized.count == 6 else {
187
+ return nil
188
+ }
189
+
190
+ return UIColor(
191
+ red: CGFloat((rgb & 0xFF0000) >> 16) / 255.0,
192
+ green: CGFloat((rgb & 0x00FF00) >> 8) / 255.0,
193
+ blue: CGFloat(rgb & 0x0000FF) / 255.0,
194
+ alpha: 1.0
195
+ )
196
+
197
+ }
198
+
199
+ }