@mapsindoors/react-native-maps-indoors-mapbox 2.8.1-rc.1 → 2.9.1
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/README.md +118 -1
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/mapsindoorsrn/MapsIndoorsPackage.java +10 -0
- package/android/src/main/java/com/mapsindoorsrn/core/BaseMapCacheProviders.java +94 -0
- package/android/src/main/java/com/mapsindoorsrn/core/DirectionsRendererModule.java +140 -49
- package/android/src/main/java/com/mapsindoorsrn/core/DirectionsServiceModule.java +16 -7
- package/android/src/main/java/com/mapsindoorsrn/core/MPDisplayRuleModule.java +1 -1
- package/android/src/main/java/com/mapsindoorsrn/core/MapControlModule.java +115 -20
- package/android/src/main/java/com/mapsindoorsrn/core/MapsIndoorsModule.java +200 -11
- package/android/src/main/java/com/mapsindoorsrn/core/RnGson.java +110 -0
- package/android/src/main/java/com/mapsindoorsrn/core/UtilsModule.java +1 -1
- package/android/src/main/java/com/mapsindoorsrn/core/models/DirectionsRendererOptionsModel.java +498 -0
- package/index.ts +25 -0
- package/ios/.swift-format +79 -0
- package/ios/core/DirectionsRendererBridge.m +11 -0
- package/ios/core/DirectionsRendererModule.swift +352 -210
- package/ios/core/DirectionsRendererOptions.swift +352 -0
- package/ios/core/MapControlModule.swift +326 -244
- package/ios/core/MapsIndoorsBridge.m +14 -1
- package/ios/core/MapsIndoorsData.swift +1 -0
- package/ios/core/MapsIndoorsModule.swift +195 -33
- package/ios/core/Sources/MainThread/CallGeneration.swift +38 -0
- package/ios/core/Sources/MainThread/MainThread.swift +25 -0
- package/ios/core/UtilsModule.swift +57 -45
- package/package.json +5 -1
- package/react-native-maps-indoors-mapbox.podspec +6 -2
- package/specs/NativeDirectionsRendererModule.ts +3 -0
- package/specs/NativeMapsIndoorsModule.ts +6 -1
- package/src/core/EventNames.ts +3 -0
- package/src/core/MPCameraPosition.ts +1 -1
- package/src/core/MPDirectionsRenderer.ts +88 -3
- package/src/core/MPDirectionsRendererOptions.ts +287 -0
- package/src/core/MPError.ts +48 -1
- package/src/core/MPLanguageTag.ts +222 -0
- package/src/core/MPLegBoundaryIcons.ts +130 -0
- package/src/core/MPRouteAnimationType.ts +24 -0
- package/src/core/MPRouteArrowStyle.ts +28 -0
- package/src/core/MPRouteMarkerDisplayRule.ts +140 -0
- package/src/core/MPRouteStampType.ts +24 -0
- package/src/core/MPRouteStopIconConfig.ts +5 -3
- package/src/core/MPSolution.ts +33 -2
- package/src/core/MPStrokeStyle.ts +22 -0
- package/src/core/MapsIndoors.ts +155 -11
- package/src/core/OnBaseMapCacheProgressListener.ts +20 -0
- package/src/core/RouteStopIconConfig.ts +5 -1
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
//
|
|
2
|
+
// DirectionsRendererOptions.swift
|
|
3
|
+
// react-native-maps-indoors
|
|
4
|
+
//
|
|
5
|
+
|
|
6
|
+
import Foundation
|
|
7
|
+
import MapsIndoors
|
|
8
|
+
import UIKit
|
|
9
|
+
|
|
10
|
+
/// The flat directions renderer options as they cross the React Native bridge.
|
|
11
|
+
///
|
|
12
|
+
/// Mirrors ``MPDirectionsRendererOptions``, with colors as hex strings, icons as URL strings and
|
|
13
|
+
/// enums as their raw wire values. Every field is optional, so an option the app left out stays
|
|
14
|
+
/// `nil` and is inherited from the solution config, or from the SDK's built-in default.
|
|
15
|
+
struct DirectionsRendererOptions: Codable {
|
|
16
|
+
var strokeColor: String?
|
|
17
|
+
var strokeOpacity: Double?
|
|
18
|
+
var strokeWeight: Double?
|
|
19
|
+
var strokeStyle: String?
|
|
20
|
+
var backgroundColorEnabled: Bool?
|
|
21
|
+
var backgroundColor: String?
|
|
22
|
+
var backgroundColorOpacity: Double?
|
|
23
|
+
var backgroundColorWeight: Double?
|
|
24
|
+
var animationType: String?
|
|
25
|
+
var animationSpeed: Double?
|
|
26
|
+
var animationMinDuration: Double?
|
|
27
|
+
var animationRepeating: Bool?
|
|
28
|
+
var forceAnimation: Bool?
|
|
29
|
+
var animatedOverlayColor: String?
|
|
30
|
+
var animatedOverlayOpacity: Double?
|
|
31
|
+
var animatedOverlayWeight: Double?
|
|
32
|
+
var stampType: String?
|
|
33
|
+
var stampImageUrl: String?
|
|
34
|
+
var stampSpacing: Double?
|
|
35
|
+
var stampScale: Double?
|
|
36
|
+
var arrowStyle: String?
|
|
37
|
+
var stampColor: String?
|
|
38
|
+
var startDisplayRule: RouteMarkerDisplayRule?
|
|
39
|
+
var endDisplayRule: RouteMarkerDisplayRule?
|
|
40
|
+
var legBoundaryIcons: LegBoundaryIcons?
|
|
41
|
+
var elevated: Bool?
|
|
42
|
+
var elevationHeight: Double?
|
|
43
|
+
var fitBoundsMaxZoom: Double?
|
|
44
|
+
|
|
45
|
+
/// The styling of a route's origin or destination marker.
|
|
46
|
+
struct RouteMarkerDisplayRule: Codable {
|
|
47
|
+
var iconUrl: String?
|
|
48
|
+
var iconVisible: Bool?
|
|
49
|
+
var iconSize: IconSize?
|
|
50
|
+
var label: String?
|
|
51
|
+
var labelVisible: Bool?
|
|
52
|
+
var labelTextSize: Double?
|
|
53
|
+
var labelTextColor: String?
|
|
54
|
+
var labelHaloColor: String?
|
|
55
|
+
var labelHaloWidth: Double?
|
|
56
|
+
var zoomFrom: Double?
|
|
57
|
+
var zoomTo: Double?
|
|
58
|
+
|
|
59
|
+
func toMPRouteMarkerDisplayRule() -> MPRouteMarkerDisplayRule {
|
|
60
|
+
let rule = MPRouteMarkerDisplayRule()
|
|
61
|
+
rule.iconUrl = iconUrl.flatMap { URL(string: $0) }
|
|
62
|
+
rule.iconVisible = iconVisible.map { NSNumber(value: $0) }
|
|
63
|
+
rule.iconSize = iconSize.flatMap { $0.toCGSize() }
|
|
64
|
+
rule.label = label
|
|
65
|
+
rule.labelVisible = labelVisible.map { NSNumber(value: $0) }
|
|
66
|
+
rule.labelTextSize = labelTextSize.map { NSNumber(value: $0) }
|
|
67
|
+
rule.labelTextColor = labelTextColor.flatMap { UIColor(hex: $0) }
|
|
68
|
+
rule.labelHaloColor = labelHaloColor.flatMap { UIColor(hex: $0) }
|
|
69
|
+
rule.labelHaloWidth = labelHaloWidth.map { NSNumber(value: $0) }
|
|
70
|
+
rule.zoomFrom = zoomFrom.map { NSNumber(value: $0) }
|
|
71
|
+
rule.zoomTo = zoomTo.map { NSNumber(value: $0) }
|
|
72
|
+
return rule
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
init() {}
|
|
76
|
+
|
|
77
|
+
init(from rule: MPRouteMarkerDisplayRule) {
|
|
78
|
+
iconUrl = rule.iconUrl?.absoluteString
|
|
79
|
+
iconVisible = rule.iconVisible?.boolValue
|
|
80
|
+
iconSize = rule.iconSize.map { IconSize(from: $0) }
|
|
81
|
+
label = rule.label
|
|
82
|
+
labelVisible = rule.labelVisible?.boolValue
|
|
83
|
+
labelTextSize = rule.labelTextSize?.doubleValue
|
|
84
|
+
labelTextColor = rule.labelTextColor.flatMap { $0.hexString }
|
|
85
|
+
labelHaloColor = rule.labelHaloColor.flatMap { $0.hexString }
|
|
86
|
+
labelHaloWidth = rule.labelHaloWidth?.doubleValue
|
|
87
|
+
zoomFrom = rule.zoomFrom?.doubleValue
|
|
88
|
+
zoomTo = rule.zoomTo?.doubleValue
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/// Explicit icon dimensions in points.
|
|
93
|
+
struct IconSize: Codable {
|
|
94
|
+
var width: Double?
|
|
95
|
+
var height: Double?
|
|
96
|
+
|
|
97
|
+
/// The size, or `nil` when either dimension is missing.
|
|
98
|
+
///
|
|
99
|
+
/// ``MPRouteMarkerDisplayRule/iconSize`` is a whole `CGSize`, so a half-specified size cannot
|
|
100
|
+
/// be expressed. Substituting `0` for the missing half would hide the marker; leaving the whole
|
|
101
|
+
/// size unset keeps it inherited, which is what an unspecified dimension means on Android too.
|
|
102
|
+
func toCGSize() -> CGSize? {
|
|
103
|
+
guard let width, let height else { return nil }
|
|
104
|
+
return CGSize(width: width, height: height)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
init(from size: CGSize) {
|
|
108
|
+
width = size.width
|
|
109
|
+
height = size.height
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/// Per connector type leg boundary icons.
|
|
114
|
+
struct LegBoundaryIcons: Codable {
|
|
115
|
+
var defaultIcon: String?
|
|
116
|
+
var elevator: String?
|
|
117
|
+
var escalator: String?
|
|
118
|
+
var stairs: String?
|
|
119
|
+
var ramp: String?
|
|
120
|
+
var wheelchairRamp: String?
|
|
121
|
+
var wheelchairLift: String?
|
|
122
|
+
var ladder: String?
|
|
123
|
+
var entry: String?
|
|
124
|
+
var scale: Double?
|
|
125
|
+
|
|
126
|
+
func toMPLegBoundaryIcons() -> MPLegBoundaryIcons {
|
|
127
|
+
let icons = MPLegBoundaryIcons()
|
|
128
|
+
icons.defaultIcon = defaultIcon.flatMap { URL(string: $0) }
|
|
129
|
+
icons.elevator = elevator.flatMap { URL(string: $0) }
|
|
130
|
+
icons.escalator = escalator.flatMap { URL(string: $0) }
|
|
131
|
+
icons.stairs = stairs.flatMap { URL(string: $0) }
|
|
132
|
+
icons.ramp = ramp.flatMap { URL(string: $0) }
|
|
133
|
+
icons.wheelchairRamp = wheelchairRamp.flatMap { URL(string: $0) }
|
|
134
|
+
icons.wheelchairLift = wheelchairLift.flatMap { URL(string: $0) }
|
|
135
|
+
icons.ladder = ladder.flatMap { URL(string: $0) }
|
|
136
|
+
icons.entry = entry.flatMap { URL(string: $0) }
|
|
137
|
+
if let scale {
|
|
138
|
+
icons.scale = scale
|
|
139
|
+
}
|
|
140
|
+
return icons
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
init() {}
|
|
144
|
+
|
|
145
|
+
init(from icons: MPLegBoundaryIcons) {
|
|
146
|
+
defaultIcon = icons.defaultIcon?.absoluteString
|
|
147
|
+
elevator = icons.elevator?.absoluteString
|
|
148
|
+
escalator = icons.escalator?.absoluteString
|
|
149
|
+
stairs = icons.stairs?.absoluteString
|
|
150
|
+
ramp = icons.ramp?.absoluteString
|
|
151
|
+
wheelchairRamp = icons.wheelchairRamp?.absoluteString
|
|
152
|
+
wheelchairLift = icons.wheelchairLift?.absoluteString
|
|
153
|
+
ladder = icons.ladder?.absoluteString
|
|
154
|
+
entry = icons.entry?.absoluteString
|
|
155
|
+
scale = icons.scale
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/// Builds the SDK's options object.
|
|
160
|
+
///
|
|
161
|
+
/// Every unset property is left `nil`, which is what makes an option the app omitted *inherited*
|
|
162
|
+
/// rather than reset: the iOS SDK resolves each property independently as app-set -> CMS
|
|
163
|
+
/// solution default -> built-in default, so assigning this whole object overrides only the
|
|
164
|
+
/// properties it actually sets. The Android module has to reconstruct that resolution by hand,
|
|
165
|
+
/// because its SDK merges a runtime config over the solution config whole-block.
|
|
166
|
+
///
|
|
167
|
+
/// - Parameter stampImage: the already downloaded icon for a custom stamp, since
|
|
168
|
+
/// ``MPDirectionsRendererOptions/stampImage`` takes a `UIImage` rather than a URL.
|
|
169
|
+
func toMPDirectionsRendererOptions(stampImage: UIImage? = nil) -> MPDirectionsRendererOptions {
|
|
170
|
+
let options = MPDirectionsRendererOptions()
|
|
171
|
+
options.strokeColor = strokeColor.flatMap { UIColor(hex: $0) }
|
|
172
|
+
options.strokeOpacity = strokeOpacity.map { NSNumber(value: $0) }
|
|
173
|
+
options.strokeWeight = strokeWeight.map { NSNumber(value: $0) }
|
|
174
|
+
options.strokeStyle = strokeStyle.flatMap { DirectionsRendererOptions.strokeStyle(from: $0) }
|
|
175
|
+
options.backgroundColorEnabled = backgroundColorEnabled.map { NSNumber(value: $0) }
|
|
176
|
+
options.backgroundColor = backgroundColor.flatMap { UIColor(hex: $0) }
|
|
177
|
+
options.backgroundColorOpacity = backgroundColorOpacity.map { NSNumber(value: $0) }
|
|
178
|
+
options.backgroundColorWeight = backgroundColorWeight.map { NSNumber(value: $0) }
|
|
179
|
+
options.animationType = animationType.flatMap { DirectionsRendererOptions.animationType(from: $0) }
|
|
180
|
+
options.animationSpeed = animationSpeed.map { NSNumber(value: $0) }
|
|
181
|
+
options.animationMinDuration = animationMinDuration.map { NSNumber(value: $0) }
|
|
182
|
+
if let animationRepeating {
|
|
183
|
+
options.animationRepeating = animationRepeating
|
|
184
|
+
}
|
|
185
|
+
options.forceAnimation = forceAnimation.map { NSNumber(value: $0) }
|
|
186
|
+
options.animatedOverlayColor = animatedOverlayColor.flatMap { UIColor(hex: $0) }
|
|
187
|
+
options.animatedOverlayOpacity = animatedOverlayOpacity.map { NSNumber(value: $0) }
|
|
188
|
+
options.animatedOverlayWeight = animatedOverlayWeight.map { NSNumber(value: $0) }
|
|
189
|
+
options.stampType = stampType.flatMap { DirectionsRendererOptions.stampType(from: $0) }
|
|
190
|
+
options.stampImage = stampImage
|
|
191
|
+
options.stampSpacing = stampSpacing.map { NSNumber(value: $0) }
|
|
192
|
+
options.stampScale = stampScale.map { NSNumber(value: $0) }
|
|
193
|
+
options.arrowStyle = arrowStyle.flatMap { DirectionsRendererOptions.arrowStyle(from: $0) }
|
|
194
|
+
options.stampColor = stampColor.flatMap { UIColor(hex: $0) }
|
|
195
|
+
options.startDisplayRule = startDisplayRule?.toMPRouteMarkerDisplayRule()
|
|
196
|
+
options.endDisplayRule = endDisplayRule?.toMPRouteMarkerDisplayRule()
|
|
197
|
+
options.legBoundaryIcons = legBoundaryIcons?.toMPLegBoundaryIcons()
|
|
198
|
+
options.elevated = elevated.map { NSNumber(value: $0) }
|
|
199
|
+
options.elevationHeight = elevationHeight.map { NSNumber(value: $0) }
|
|
200
|
+
options.fitBoundsMaxZoom = fitBoundsMaxZoom.map { NSNumber(value: $0) }
|
|
201
|
+
return options
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
init() {}
|
|
205
|
+
|
|
206
|
+
/// Flattens the options the renderer currently holds back into the bridge's shape.
|
|
207
|
+
///
|
|
208
|
+
/// - Parameter stampImageUrl: the URL of the custom stamp last applied through this bridge. The SDK
|
|
209
|
+
/// holds the downloaded `UIImage` rather than its URL, so it cannot be recovered from `options` -
|
|
210
|
+
/// without it a read-modify-write would feed back `stampType == .custom` with no image and silently
|
|
211
|
+
/// drop the stamp. When the URL is unknown, ``stampType`` is reported as `nil` instead, so the pair
|
|
212
|
+
/// stays self-consistent and the stamp is inherited rather than blanked.
|
|
213
|
+
init(from options: MPDirectionsRendererOptions, stampImageUrl: String? = nil) {
|
|
214
|
+
strokeColor = options.strokeColor.flatMap { $0.hexString }
|
|
215
|
+
strokeOpacity = options.strokeOpacity?.doubleValue
|
|
216
|
+
strokeWeight = options.strokeWeight?.doubleValue
|
|
217
|
+
strokeStyle = options.strokeStyle.map { DirectionsRendererOptions.string(from: $0) }
|
|
218
|
+
backgroundColorEnabled = options.backgroundColorEnabled?.boolValue
|
|
219
|
+
backgroundColor = options.backgroundColor.flatMap { $0.hexString }
|
|
220
|
+
backgroundColorOpacity = options.backgroundColorOpacity?.doubleValue
|
|
221
|
+
backgroundColorWeight = options.backgroundColorWeight?.doubleValue
|
|
222
|
+
animationType = options.animationType.map { DirectionsRendererOptions.string(from: $0) }
|
|
223
|
+
animationSpeed = options.animationSpeed?.doubleValue
|
|
224
|
+
animationMinDuration = options.animationMinDuration?.doubleValue
|
|
225
|
+
animationRepeating = options.animationRepeating
|
|
226
|
+
forceAnimation = options.forceAnimation?.boolValue
|
|
227
|
+
animatedOverlayColor = options.animatedOverlayColor.flatMap { $0.hexString }
|
|
228
|
+
animatedOverlayOpacity = options.animatedOverlayOpacity?.doubleValue
|
|
229
|
+
animatedOverlayWeight = options.animatedOverlayWeight?.doubleValue
|
|
230
|
+
self.stampImageUrl = stampImageUrl
|
|
231
|
+
let resolvedStampType = options.stampType.map { DirectionsRendererOptions.string(from: $0) }
|
|
232
|
+
stampType = resolvedStampType == "custom" && stampImageUrl == nil ? nil : resolvedStampType
|
|
233
|
+
stampSpacing = options.stampSpacing?.doubleValue
|
|
234
|
+
stampScale = options.stampScale?.doubleValue
|
|
235
|
+
arrowStyle = options.arrowStyle.map { DirectionsRendererOptions.string(from: $0) }
|
|
236
|
+
stampColor = options.stampColor.flatMap { $0.hexString }
|
|
237
|
+
startDisplayRule = options.startDisplayRule.map { RouteMarkerDisplayRule(from: $0) }
|
|
238
|
+
endDisplayRule = options.endDisplayRule.map { RouteMarkerDisplayRule(from: $0) }
|
|
239
|
+
legBoundaryIcons = options.legBoundaryIcons.map { LegBoundaryIcons(from: $0) }
|
|
240
|
+
elevated = options.elevated?.boolValue
|
|
241
|
+
elevationHeight = options.elevationHeight?.doubleValue
|
|
242
|
+
fitBoundsMaxZoom = options.fitBoundsMaxZoom?.doubleValue
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// MARK: - Enum mapping
|
|
246
|
+
|
|
247
|
+
private static func strokeStyle(from value: String) -> MPStrokeStyle? {
|
|
248
|
+
switch value {
|
|
249
|
+
case "solid": return .solid
|
|
250
|
+
case "dashed": return .dashed
|
|
251
|
+
case "dotted": return .dotted
|
|
252
|
+
default: return nil
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
private static func string(from value: MPStrokeStyle) -> String {
|
|
257
|
+
switch value {
|
|
258
|
+
case .solid: return "solid"
|
|
259
|
+
case .dashed: return "dashed"
|
|
260
|
+
case .dotted: return "dotted"
|
|
261
|
+
@unknown default: return "solid"
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
private static func animationType(from value: String) -> MPRouteAnimationType? {
|
|
266
|
+
switch value {
|
|
267
|
+
case "none": return MPRouteAnimationType.none
|
|
268
|
+
case "flow": return .flow
|
|
269
|
+
case "pulse": return .pulse
|
|
270
|
+
case "comet": return .comet
|
|
271
|
+
default: return nil
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
private static func string(from value: MPRouteAnimationType) -> String {
|
|
276
|
+
switch value {
|
|
277
|
+
case .none: return "none"
|
|
278
|
+
case .flow: return "flow"
|
|
279
|
+
case .pulse: return "pulse"
|
|
280
|
+
case .comet: return "comet"
|
|
281
|
+
@unknown default: return "flow"
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
private static func stampType(from value: String) -> MPRouteStampType? {
|
|
286
|
+
switch value {
|
|
287
|
+
case "none": return MPRouteStampType.none
|
|
288
|
+
case "arrow": return .arrow
|
|
289
|
+
case "custom": return .custom
|
|
290
|
+
default: return nil
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
private static func string(from value: MPRouteStampType) -> String {
|
|
295
|
+
switch value {
|
|
296
|
+
case .none: return "none"
|
|
297
|
+
case .arrow: return "arrow"
|
|
298
|
+
case .custom: return "custom"
|
|
299
|
+
@unknown default: return "none"
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
private static func arrowStyle(from value: String) -> MPRouteArrowStyle? {
|
|
304
|
+
switch value {
|
|
305
|
+
case "chevron": return .chevron
|
|
306
|
+
case "chevronDouble": return .chevronDouble
|
|
307
|
+
case "triangle": return .triangle
|
|
308
|
+
case "arrow": return .arrow
|
|
309
|
+
case "dart": return .dart
|
|
310
|
+
default: return nil
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
private static func string(from value: MPRouteArrowStyle) -> String {
|
|
315
|
+
switch value {
|
|
316
|
+
case .chevron: return "chevron"
|
|
317
|
+
case .chevronDouble: return "chevronDouble"
|
|
318
|
+
case .triangle: return "triangle"
|
|
319
|
+
case .arrow: return "arrow"
|
|
320
|
+
case .dart: return "dart"
|
|
321
|
+
@unknown default: return "chevron"
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
extension UIColor {
|
|
327
|
+
/// The color as an `#RRGGBB` hex string, or `nil` when it has no describable components.
|
|
328
|
+
///
|
|
329
|
+
/// The bridge keeps colors opaque and carries transparency in the separate opacity options, so
|
|
330
|
+
/// that a color reads back the same on both platforms - the two SDKs disagree on where the
|
|
331
|
+
/// alpha component of an 8 digit hex string sits.
|
|
332
|
+
var hexString: String? {
|
|
333
|
+
let component = { (value: CGFloat) in Int((max(0, min(1, value)) * 255).rounded()) }
|
|
334
|
+
|
|
335
|
+
var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0
|
|
336
|
+
if getRed(&red, green: &green, blue: &blue, alpha: &alpha) {
|
|
337
|
+
return String(format: "#%02X%02X%02X", component(red), component(green), component(blue))
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// A monochrome colour has no RGB components to report, so ask for its white level and
|
|
341
|
+
// describe it as the equivalent grey rather than failing.
|
|
342
|
+
var white: CGFloat = 0
|
|
343
|
+
if getWhite(&white, alpha: &alpha) {
|
|
344
|
+
let level = component(white)
|
|
345
|
+
return String(format: "#%02X%02X%02X", level, level, level)
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// A pattern colour, or anything else with no numeric components: report it as absent rather
|
|
349
|
+
// than inventing black, which would read back as a colour the app never set.
|
|
350
|
+
return nil
|
|
351
|
+
}
|
|
352
|
+
}
|