Skip to content

Commit d1e7673

Browse files
evil159github-actions[bot]
authored andcommitted
[gl-native] Generate swift bindings for StylePropertyValue (#10247)
`StylePropertyValue` is used in swift_compat bindings in mapbox/mapbox-sdk#10204 cc @mapbox/core-sdk cc @mapbox/gl-native cc @mapbox/maps-ios cc @mapbox/maps-android cc @mapbox/nav-core-sdk GitOrigin-RevId: 3cf38febefb400969670d87b82e7872d70896d4d
1 parent 70ff356 commit d1e7673

7 files changed

Lines changed: 67 additions & 45 deletions

File tree

Sources/MapboxMaps/Foundation/CoreAliases.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ typealias CoreColorTheme = MapboxCoreMaps_Private.ColorTheme
5050
typealias CoreAsyncOperationResultCallback = MapboxCoreMaps_Private.AsyncOperationResultCallback
5151
typealias UIEdgeInsetsCodable = MapboxCoreMaps.UIEdgeInsetsCodable
5252
typealias CoreIndoorManager = MapboxCoreMaps_Private.__IndoorManager
53+
typealias CoreStylePropertyValue = MapboxCoreMaps_Private.__StylePropertyValue

Sources/MapboxMaps/Style/ColorTheme.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import UIKit
2+
@_spi(Marshalling) import MapboxCoreMaps
23

34
/// Map color theme.
45
///
@@ -59,6 +60,21 @@ public struct ColorTheme: Equatable {
5960
self.uiimage = uiimage
6061
self.base64 = nil
6162
}
63+
64+
public static func == (lhs: ColorTheme, rhs: ColorTheme) -> Bool {
65+
switch (lhs.base64?.value, rhs.base64?.value) {
66+
case (let lhse as any Equatable, let rhse as any Equatable):
67+
func isEqual<T: Equatable>(_ lhs: T, _ rhs: any Equatable) -> Bool {
68+
lhs == rhs as? T
69+
}
70+
return isEqual(lhse, rhse) && lhs.uiimage == rhs.uiimage
71+
72+
case (.none, .none):
73+
return lhs.uiimage == rhs.uiimage
74+
default:
75+
return false
76+
}
77+
}
6278
}
6379

6480
@available(iOS 13.0, *)
@@ -71,7 +87,7 @@ extension ColorTheme: MapStyleContent, PrimitiveMapContent {
7187
extension ColorTheme {
7288
var core: CoreColorTheme? {
7389
if let base64 {
74-
return .fromStylePropertyValue(base64)
90+
return .fromStylePropertyValue(StylePropertyValue.Marshaller.toObjc(base64))
7591
} else if let uiimage, let coreImage = CoreMapsImage(uiImage: uiimage) {
7692
return .fromImage(coreImage)
7793
} else {

Sources/MapboxMaps/Style/StyleManager.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -645,9 +645,10 @@ public class StyleManager {
645645
/// - Returns:
646646
/// - The style import configuration or a string describing an error if the operation was not successful.
647647
public func getStyleImportConfigProperties(for importId: String) throws -> [String: StylePropertyValue] {
648-
try handleExpected {
648+
let result: [String: CoreStylePropertyValue] = try handleExpected {
649649
return styleManager.getStyleImportConfigProperties(forImportId: importId)
650650
}
651+
return result.mapValues(StylePropertyValue.Marshaller.toSwift)
651652
}
652653

653654
/// Gets the value of style import config.
@@ -659,9 +660,10 @@ public class StyleManager {
659660
/// - Returns:
660661
/// - The style import configuration or a string describing an error if the operation was not successful.
661662
public func getStyleImportConfigProperty(for importId: String, config: String) throws -> StylePropertyValue {
662-
try handleExpected {
663+
let result: CoreStylePropertyValue = try handleExpected {
663664
return styleManager.getStyleImportConfigProperty(forImportId: importId, config: config)
664665
}
666+
return StylePropertyValue.Marshaller.toSwift(result)
665667
}
666668

667669
/// Sets style import config.
@@ -873,7 +875,7 @@ public class StyleManager {
873875
/// - Returns:
874876
/// The value of the property in the layer with layerId.
875877
public func layerProperty(for layerId: String, property: String) -> StylePropertyValue {
876-
return styleManager.getStyleLayerProperty(forLayerId: layerId, property: property)
878+
return StylePropertyValue.Marshaller.toSwift(styleManager.getStyleLayerProperty(forLayerId: layerId, property: property))
877879
}
878880

879881
/// Sets a JSON value to a style layer property.
@@ -916,7 +918,7 @@ public class StyleManager {
916918
/// - Returns:
917919
/// The default value of the property for the layers with type layerType.
918920
public static func layerPropertyDefaultValue(for layerType: LayerType, property: String) -> StylePropertyValue {
919-
return CoreStyleManager.getStyleLayerPropertyDefaultValue(forLayerType: layerType.rawValue, property: property)
921+
return StylePropertyValue.Marshaller.toSwift(CoreStyleManager.getStyleLayerPropertyDefaultValue(forLayerType: layerType.rawValue, property: property))
920922
}
921923

922924
/// Gets the properties for a style layer.
@@ -1251,7 +1253,7 @@ public class StyleManager {
12511253
/// - Parameter lightId: The unique identifier of the style light in lights list.
12521254
/// - Parameter property: The style light property name.
12531255
public func lightPropertyValue(for lightId: String, property: String) -> StylePropertyValue {
1254-
styleManager.getStyleLightProperty(forId: lightId, property: property)
1256+
StylePropertyValue.Marshaller.toSwift(styleManager.getStyleLightProperty(forId: lightId, property: property))
12551257
}
12561258

12571259
/// Set global directional lightning.
@@ -1345,7 +1347,7 @@ public class StyleManager {
13451347
///
13461348
/// - Returns: Style terrain property value.
13471349
public func terrainProperty(_ property: String) -> StylePropertyValue {
1348-
return styleManager.getStyleTerrainProperty(forProperty: property)
1350+
return StylePropertyValue.Marshaller.toSwift(styleManager.getStyleTerrainProperty(forProperty: property))
13491351
}
13501352

13511353
// MARK: - Atmosphere
@@ -1405,7 +1407,7 @@ public class StyleManager {
14051407
///
14061408
/// - Returns: Style atmosphere property value.
14071409
public func atmosphereProperty(_ property: String) -> StylePropertyValue {
1408-
return styleManager.getStyleAtmosphereProperty(forProperty: property)
1410+
return StylePropertyValue.Marshaller.toSwift(styleManager.getStyleAtmosphereProperty(forProperty: property))
14091411
}
14101412

14111413
// MARK: Model

Sources/MapboxMaps/Style/StyleManagerProtocol.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ internal protocol StyleManagerProtocol {
3131
func getStyleImportConfigProperties(forImportId importId: String) -> Expected<NSDictionary, NSString>
3232
func getStyleImportConfigProperty(
3333
forImportId importId: String,
34-
config: String) -> Expected<MapboxCoreMaps.StylePropertyValue, NSString>
34+
config: String) -> Expected<CoreStylePropertyValue, NSString>
3535
func setStyleImportConfigPropertiesForImportId(_ importId: String, configs: [String: Any]) -> Expected<NSNull, NSString>
3636
func setStyleImportConfigPropertyForImportId(_ importId: String, config: String, value: Any) -> Expected<NSNull, NSString>
3737

@@ -47,15 +47,15 @@ internal protocol StyleManagerProtocol {
4747
func getStyleLayers() -> [MapboxCoreMaps.StyleObjectInfo]
4848
func getStyleSlots() -> [String]
4949

50-
func getStyleLayerProperty(forLayerId layerId: String, property: String) -> MapboxCoreMaps.StylePropertyValue
50+
func getStyleLayerProperty(forLayerId layerId: String, property: String) -> CoreStylePropertyValue
5151

52-
func getStyleSourceProperty(forSourceId sourceId: String, property: String) -> MapboxCoreMaps.StylePropertyValue
52+
func getStyleSourceProperty(forSourceId sourceId: String, property: String) -> CoreStylePropertyValue
5353

5454
func styleSourceExists(forSourceId sourceId: String) -> Bool
5555
func getStyleSources() -> [MapboxCoreMaps.StyleObjectInfo]
5656

57-
func getStyleTerrainProperty(forProperty property: String) -> MapboxCoreMaps.StylePropertyValue
58-
func getStyleProjectionProperty(forProperty property: String) -> MapboxCoreMaps.StylePropertyValue
57+
func getStyleTerrainProperty(forProperty property: String) -> CoreStylePropertyValue
58+
func getStyleProjectionProperty(forProperty property: String) -> CoreStylePropertyValue
5959

6060
func getStyleImage(forImageId imageId: String) -> CoreMapsImage?
6161
func hasStyleImage(forImageId imageId: String) -> Bool
@@ -134,7 +134,7 @@ internal protocol StyleManagerProtocol {
134134
// 3D Light
135135
func getStyleLights() -> [StyleObjectInfo]
136136
func setStyleLightsForLights(_ lights: Any) -> Expected<NSNull, NSString>
137-
func getStyleLightProperty(forId id: String, property: String) -> StylePropertyValue
137+
func getStyleLightProperty(forId id: String, property: String) -> CoreStylePropertyValue
138138
func setStyleLightPropertyForId(_ id: String, property: String, value: Any) -> Expected<NSNull, NSString>
139139

140140
@discardableResult
@@ -152,11 +152,11 @@ internal protocol StyleManagerProtocol {
152152

153153
// Snow
154154
func setStyleSnowForProperties(_ properties: Any) -> Expected<NSNull, NSString>
155-
func getStyleSnowProperty(forProperty: String) -> StylePropertyValue
155+
func getStyleSnowProperty(forProperty: String) -> CoreStylePropertyValue
156156

157157
// Rain
158158
func setStyleRainForProperties(_ properties: Any) -> Expected<NSNull, NSString>
159-
func getStyleRainProperty(forProperty: String) -> StylePropertyValue
159+
func getStyleRainProperty(forProperty: String) -> CoreStylePropertyValue
160160

161161
// Style Model API
162162
func addStyleModel(forModelId modelId: String, modelUri: String) -> Expected<NSNull, NSString>
@@ -210,7 +210,7 @@ internal protocol StyleManagerProtocol {
210210

211211
func setStyleAtmospherePropertyForProperty(_ property: String, value: Any) -> Expected<NSNull, NSString>
212212

213-
func getStyleAtmosphereProperty(forProperty: String) -> StylePropertyValue
213+
func getStyleAtmosphereProperty(forProperty: String) -> CoreStylePropertyValue
214214
func addGeoJSONSourceFeatures(forSourceId sourceId: String,
215215
dataId: String,
216216
features: [MapboxCommon.Feature]) -> Expected<NSNull, NSString>

Sources/MapboxMaps/Style/StyleSourceManager.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Foundation
22
@_implementationOnly import MapboxCommon_Private
3+
@_spi(Marshalling) import MapboxCoreMaps
34

45
internal protocol StyleSourceManagerProtocol: AnyObject {
56
static func sourcePropertyDefaultValue(for sourceType: String, property: String) -> StylePropertyValue
@@ -26,7 +27,7 @@ internal final class StyleSourceManager: StyleSourceManagerProtocol {
2627
private typealias SourceId = String
2728

2829
internal static func sourcePropertyDefaultValue(for sourceType: String, property: String) -> StylePropertyValue {
29-
return CoreStyleManager.getStyleSourcePropertyDefaultValue(forSourceType: sourceType, property: property)
30+
return StylePropertyValue.Marshaller.toSwift(CoreStyleManager.getStyleSourcePropertyDefaultValue(forSourceType: sourceType, property: property))
3031
}
3132

3233
private let styleManager: StyleManagerProtocol
@@ -242,7 +243,7 @@ internal final class StyleSourceManager: StyleSourceManagerProtocol {
242243
}
243244

244245
internal func sourceProperty(for sourceId: String, property: String) -> StylePropertyValue {
245-
return styleManager.getStyleSourceProperty(forSourceId: sourceId, property: property)
246+
return StylePropertyValue.Marshaller.toSwift(styleManager.getStyleSourceProperty(forSourceId: sourceId, property: property))
246247
}
247248

248249
internal func sourceProperties(for sourceId: String) throws -> [String: Any] {

Tests/MapboxMapsTests/Foundation/Mocks/MockStyleManager.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ class MockStyleManager: StyleManagerProtocol {
109109
}
110110

111111
typealias GetStyleLayerPropertyParameters = (layerID: String, property: String)
112-
let getStyleLayerPropertyStub = Stub<GetStyleLayerPropertyParameters, StylePropertyValue>(
113-
defaultReturnValue: StylePropertyValue(value: "foo", kind: .undefined)
112+
let getStyleLayerPropertyStub = Stub<GetStyleLayerPropertyParameters, CoreStylePropertyValue>(
113+
defaultReturnValue: CoreStylePropertyValue(value: "foo", kind: .undefined)
114114
)
115115
func getStyleLayerProperty(
116116
forLayerId layerId: String,
117117
property: String
118-
) -> MapboxCoreMaps.StylePropertyValue {
118+
) -> CoreStylePropertyValue {
119119

120120
getStyleLayerPropertyStub.call(with: (layerID: layerId, property: property))
121121
}
@@ -126,10 +126,10 @@ class MockStyleManager: StyleManagerProtocol {
126126
let sourceId: String
127127
let property: String
128128
}
129-
let getStyleSourcePropertyStub = Stub<GetStyleSourcePropertyParameters, MapboxCoreMaps.StylePropertyValue>(
129+
let getStyleSourcePropertyStub = Stub<GetStyleSourcePropertyParameters, CoreStylePropertyValue>(
130130
defaultReturnValue: .init(value: "stub", kind: .undefined)
131131
)
132-
func getStyleSourceProperty(forSourceId sourceId: String, property: String) -> MapboxCoreMaps.StylePropertyValue {
132+
func getStyleSourceProperty(forSourceId sourceId: String, property: String) -> CoreStylePropertyValue {
133133
getStyleSourcePropertyStub.call(with: GetStyleSourcePropertyParameters(sourceId: sourceId, property: property))
134134
}
135135

@@ -143,10 +143,10 @@ class MockStyleManager: StyleManagerProtocol {
143143
getStyleSourcesStub.call()
144144
}
145145

146-
let getStyleLightPropertyStub = Stub<String, MapboxCoreMaps.StylePropertyValue>(
146+
let getStyleLightPropertyStub = Stub<String, CoreStylePropertyValue>(
147147
defaultReturnValue: .init(value: "stub", kind: .undefined)
148148
)
149-
func getStyleLightProperty(forProperty property: String) -> MapboxCoreMaps.StylePropertyValue {
149+
func getStyleLightProperty(forProperty property: String) -> CoreStylePropertyValue {
150150
getStyleLightPropertyStub.call(with: property)
151151
}
152152

@@ -163,10 +163,10 @@ class MockStyleManager: StyleManagerProtocol {
163163
struct GetStyleLightPropertyForIdParameters {
164164
let id, property: String
165165
}
166-
let getStyleLightPropertyForIdStub = Stub<GetStyleLightPropertyForIdParameters, StylePropertyValue>(
166+
let getStyleLightPropertyForIdStub = Stub<GetStyleLightPropertyForIdParameters, CoreStylePropertyValue>(
167167
defaultReturnValue: .init(value: "stub", kind: .undefined)
168168
)
169-
func getStyleLightProperty(forId id: String, property: String) -> StylePropertyValue {
169+
func getStyleLightProperty(forId id: String, property: String) -> CoreStylePropertyValue {
170170
getStyleLightPropertyForIdStub.call(with: .init(id: id, property: property))
171171
}
172172

@@ -182,18 +182,18 @@ class MockStyleManager: StyleManagerProtocol {
182182
}
183183

184184
// MARK: Terrain
185-
let getStyleTerrainPropertyStub = Stub<String, MapboxCoreMaps.StylePropertyValue>(
185+
let getStyleTerrainPropertyStub = Stub<String, CoreStylePropertyValue>(
186186
defaultReturnValue: .init(value: "stub", kind: .undefined)
187187
)
188-
func getStyleTerrainProperty(forProperty property: String) -> MapboxCoreMaps.StylePropertyValue {
188+
func getStyleTerrainProperty(forProperty property: String) -> CoreStylePropertyValue {
189189
getStyleTerrainPropertyStub.call(with: property)
190190
}
191191

192192
// MARK: Projection
193-
let getStyleProjectionPropertyStub = Stub<String, MapboxCoreMaps.StylePropertyValue>(
193+
let getStyleProjectionPropertyStub = Stub<String, CoreStylePropertyValue>(
194194
defaultReturnValue: .init(value: "stub", kind: .undefined)
195195
)
196-
func getStyleProjectionProperty(forProperty property: String) -> MapboxCoreMaps.StylePropertyValue {
196+
func getStyleProjectionProperty(forProperty property: String) -> CoreStylePropertyValue {
197197
getStyleProjectionPropertyStub.call(with: property)
198198
}
199199

@@ -204,8 +204,8 @@ class MockStyleManager: StyleManagerProtocol {
204204
setStyleSnowForPropertiesStub.call(with: properties)
205205
}
206206

207-
let getStyleSnowPropertyStub = Stub<String, StylePropertyValue>(defaultReturnValue: .init(value: "stub", kind: .undefined))
208-
func getStyleSnowProperty(forProperty: String) -> StylePropertyValue {
207+
let getStyleSnowPropertyStub = Stub<String, CoreStylePropertyValue>(defaultReturnValue: .init(value: "stub", kind: .undefined))
208+
func getStyleSnowProperty(forProperty: String) -> CoreStylePropertyValue {
209209
getStyleSnowPropertyStub.call(with: forProperty)
210210
}
211211

@@ -214,8 +214,8 @@ class MockStyleManager: StyleManagerProtocol {
214214
setStyleRainForPropertiesStub.call(with: properties)
215215
}
216216

217-
let getStyleRainPropertyStub = Stub<String, StylePropertyValue>(defaultReturnValue: .init(value: "stub", kind: .undefined))
218-
func getStyleRainProperty(forProperty: String) -> StylePropertyValue {
217+
let getStyleRainPropertyStub = Stub<String, CoreStylePropertyValue>(defaultReturnValue: .init(value: "stub", kind: .undefined))
218+
func getStyleRainProperty(forProperty: String) -> CoreStylePropertyValue {
219219
getStyleRainPropertyStub.call(with: forProperty)
220220
}
221221

@@ -262,7 +262,7 @@ class MockStyleManager: StyleManagerProtocol {
262262
struct GetStyleImportConfigPropertiesParameters {
263263
let importId: String
264264
}
265-
let getStyleImportConfigPropertiesStub = Stub<GetStyleImportConfigPropertiesParameters, Expected<NSDictionary, NSString>>(defaultReturnValue: .init(value: NSDictionary(dictionary: ["stub": StylePropertyValue.init(value: "stub", kind: .undefined)])))
265+
let getStyleImportConfigPropertiesStub = Stub<GetStyleImportConfigPropertiesParameters, Expected<NSDictionary, NSString>>(defaultReturnValue: .init(value: NSDictionary(dictionary: ["stub": CoreStylePropertyValue.init(value: "stub", kind: .undefined)])))
266266
func getStyleImportConfigProperties(forImportId importId: String) -> Expected<NSDictionary, NSString> {
267267
getStyleImportConfigPropertiesStub.call(with: GetStyleImportConfigPropertiesParameters(importId: importId))
268268
}
@@ -271,8 +271,8 @@ class MockStyleManager: StyleManagerProtocol {
271271
let importId: String
272272
let config: String
273273
}
274-
let getStyleImportConfigPropertyStub = Stub<GetStyleImportConfigPropertyParameters, Expected<MapboxCoreMaps.StylePropertyValue, NSString>>(defaultReturnValue: .init(value: .init(value: "stub", kind: .undefined)))
275-
func getStyleImportConfigProperty(forImportId importId: String, config: String) -> Expected<StylePropertyValue, NSString> {
274+
let getStyleImportConfigPropertyStub = Stub<GetStyleImportConfigPropertyParameters, Expected<CoreStylePropertyValue, NSString>>(defaultReturnValue: .init(value: .init(value: "stub", kind: .undefined)))
275+
func getStyleImportConfigProperty(forImportId importId: String, config: String) -> Expected<CoreStylePropertyValue, NSString> {
276276
getStyleImportConfigPropertyStub.call(with: GetStyleImportConfigPropertyParameters(importId: importId, config: config))
277277
}
278278

@@ -736,10 +736,10 @@ class MockStyleManager: StyleManagerProtocol {
736736
hasStyleModelStub.call(with: HasStyleModelParams(modelId: modelId))
737737
}
738738

739-
let getStyleAtmospherePropertyStub = Stub<String, MapboxCoreMaps.StylePropertyValue>(
739+
let getStyleAtmospherePropertyStub = Stub<String, CoreStylePropertyValue>(
740740
defaultReturnValue: .init(value: "stub", kind: .undefined)
741741
)
742-
func getStyleAtmosphereProperty(forProperty property: String) -> StylePropertyValue {
742+
func getStyleAtmosphereProperty(forProperty property: String) -> CoreStylePropertyValue {
743743
getStyleAtmospherePropertyStub.call(with: property)
744744
}
745745

Tests/MapboxMapsTests/Foundation/Style/StyleTests.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ final class StyleManagerTests: XCTestCase {
3737

3838
func testProjection() {
3939
let projectionName = StyleProjectionName.testConstantValue()
40-
styleManager.getStyleProjectionPropertyStub.defaultReturnValue = StylePropertyValue(
40+
styleManager.getStyleProjectionPropertyStub.defaultReturnValue = CoreStylePropertyValue(
4141
value: projectionName.rawValue,
4242
kind: .constant
4343
)
4444

4545
XCTAssertEqual(style.projection?.name, projectionName)
4646

47-
styleManager.getStyleProjectionPropertyStub.defaultReturnValue = StylePropertyValue(
47+
styleManager.getStyleProjectionPropertyStub.defaultReturnValue = CoreStylePropertyValue(
4848
value: projectionName.rawValue,
4949
kind: .undefined
5050
)
@@ -336,7 +336,8 @@ final class StyleManagerTests: XCTestCase {
336336
func testGetSourceProperty() throws {
337337
let id = String.testConstantASCII(withLength: 10)
338338
let property = String.testConstantASCII(withLength: 10)
339-
let value = StylePropertyValue(value: "foo", kind: .constant)
339+
let testValue = "foo"
340+
let value = StylePropertyValue(value: testValue, kind: .constant)
340341
sourceManager.sourcePropertyForStub.defaultReturnValue = value
341342

342343
let returnedValue = style.sourceProperty(for: id, property: property)
@@ -345,7 +346,8 @@ final class StyleManagerTests: XCTestCase {
345346
let params = try XCTUnwrap(sourceManager.sourcePropertyForStub.invocations.first?.parameters)
346347
XCTAssertEqual(params.sourceId, id)
347348
XCTAssertEqual(params.property, property)
348-
XCTAssertEqual(value, returnedValue)
349+
XCTAssertEqual(value.kind, returnedValue.kind)
350+
XCTAssertEqual(testValue, returnedValue.value as? String)
349351
}
350352

351353
func testGetSourceProperties() throws {

0 commit comments

Comments
 (0)