Skip to content

Commit 9115d7a

Browse files
evil159github-actions[bot]
authored andcommitted
[gl-native] swift bindings for camera records (#8493)
`CameraState`, `CameraOptions`, `EdgeInsets` and `ScreenCoordinate` swift definitions are moved from the iOS sdk to gl native. This is needed to be able to refer to these types in maps cpp generated swift bindings. cc @mapbox/maps-ios cc @mapbox/core-sdk cc @mapbox/gl-native GitOrigin-RevId: a7a6d3540e1ccfcef2f22e3b19fb021dc29a76ae
1 parent 52bbdb0 commit 9115d7a

27 files changed

+113
-515
lines changed

Sources/MapboxMaps/Documentation.docc/API Catalogs/CoreMapsInternal.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Maps rendering SDK also known as GL-Native. These are for internal use only.
1111
- ``Size``
1212
- ``StylePackError-class``
1313
- ``RequestErrorType``
14+
- ``EdgeInsets``
15+
- ``ScreenCoordinate``
1416

1517
<!-- functions -->
1618
- ``MBMMapLoadingErrorTypeToString(_:)``

Sources/MapboxMaps/Foundation/CameraOptions.swift

Lines changed: 0 additions & 89 deletions
This file was deleted.

Sources/MapboxMaps/Foundation/CameraState.swift

Lines changed: 0 additions & 60 deletions
This file was deleted.

Sources/MapboxMaps/Foundation/CoreAliases.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
@_implementationOnly import MapboxCoreMaps_Private
22
@_implementationOnly import MapboxCommon_Private
3+
@_spi(Internal) import MapboxCoreMaps
34

4-
typealias CoreCameraOptions = MapboxCoreMaps_Private.CameraOptions
5-
typealias CoreCameraState = MapboxCoreMaps_Private.CameraState
5+
typealias CoreCameraOptions = MapboxCoreMaps_Private.__CameraOptions
6+
typealias CoreCameraState = MapboxCoreMaps_Private.__CameraState
67
typealias CoreCameraBounds = MapboxCoreMaps_Private.CameraBounds
78
typealias CoreCameraBoundsOptions = MapboxCoreMaps_Private.CameraBoundsOptions
89
typealias CoreMapSnapshotOptions = MapboxCoreMaps_Private.MapSnapshotOptions
@@ -15,9 +16,9 @@ typealias CoreAnnotatedFeature = MapboxCoreMaps_Private.AnnotatedFeature
1516
typealias CoreAnnotatedLayerFeature = MapboxCoreMaps_Private.AnnotatedLayerFeature
1617
typealias CoreProjection = MapboxCoreMaps_Private.Projection
1718
typealias CoreMap = MapboxCoreMaps_Private.Map
18-
typealias CoreScreenCoordinate = MapboxCoreMaps_Private.ScreenCoordinate
19+
typealias CoreScreenCoordinate = MapboxCoreMaps_Private.__ScreenCoordinate
1920
typealias CoreScreenBox = MapboxCoreMaps_Private.ScreenBox
20-
typealias CoreEdgeInsets = MapboxCoreMaps_Private.EdgeInsets
21+
typealias CoreEdgeInsets = MapboxCoreMaps_Private.__EdgeInsets
2122
typealias CoreTileCoverOptions = MapboxCoreMaps_Private.TileCoverOptions
2223
typealias CoreMapsImage = MapboxCoreMaps_Private.__Image
2324
typealias CoreCustomRasterSourceTileData = MapboxCoreMaps_Private.CustomRasterSourceTileData
@@ -47,3 +48,4 @@ typealias CoreFeaturesetQueryTarget = MapboxCoreMaps_Private.FeaturesetQueryTarg
4748
typealias CoreFeaturesetDescriptor = MapboxCoreMaps_Private.FeaturesetDescriptor
4849
typealias CoreColorTheme = MapboxCoreMaps_Private.ColorTheme
4950
typealias CoreAsyncOperationResultCallback = MapboxCoreMaps_Private.AsyncOperationResultCallback
51+
typealias UIEdgeInsetsCodable = MapboxCoreMaps.UIEdgeInsetsCodable

Sources/MapboxMaps/Foundation/Extensions/CoreGraphics.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Foundation
22
import CoreLocation
33
import CoreGraphics
44
import MapboxCoreMaps
5+
@_implementationOnly import MapboxCoreMaps_Private
56

67
// MARK: - CGPoint
78
extension CGPoint {

Sources/MapboxMaps/Foundation/Helpers/CGPointCodable.swift

Lines changed: 0 additions & 22 deletions
This file was deleted.

Sources/MapboxMaps/Foundation/Helpers/CLLocationCoordinate2DCodable.swift

Lines changed: 0 additions & 22 deletions
This file was deleted.

Sources/MapboxMaps/Foundation/Helpers/UIEdgeInsetsCodable.swift

Lines changed: 0 additions & 28 deletions
This file was deleted.

Sources/MapboxMaps/Foundation/MapboxMap.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ public final class MapboxMap: StyleManager {
573573
pitch: Double?,
574574
maxZoom: Double?,
575575
offset: CGPoint?) -> CameraOptions {
576-
return CameraOptions(
576+
return CameraOptions.Marshaller.toSwift(
577577
__map.cameraForCoordinateBounds(
578578
for: coordinateBounds,
579579
padding: padding?.toMBXEdgeInsetsValue(),
@@ -630,7 +630,7 @@ public final class MapboxMap: StyleManager {
630630
padding: UIEdgeInsets?,
631631
bearing: Double?,
632632
pitch: Double?) -> CameraOptions {
633-
return CameraOptions(
633+
return CameraOptions.Marshaller.toSwift(
634634
__map.cameraForCoordinates(
635635
for: coordinates.map { Coordinate2D(value: $0) },
636636
padding: padding?.toMBXEdgeInsetsValue(),
@@ -662,10 +662,10 @@ public final class MapboxMap: StyleManager {
662662
public func camera(for coordinates: [CLLocationCoordinate2D],
663663
camera: CameraOptions,
664664
rect: CGRect) -> CameraOptions {
665-
return CameraOptions(
665+
return CameraOptions.Marshaller.toSwift(
666666
__map.cameraForCoordinates(
667667
for: coordinates.map { Coordinate2D(value: $0) },
668-
camera: CoreCameraOptions(camera),
668+
camera: CameraOptions.Marshaller.toObjc(camera),
669669
box: CoreScreenBox(rect)))
670670
}
671671

@@ -687,7 +687,7 @@ public final class MapboxMap: StyleManager {
687687
offset: CGPoint?) throws -> CameraOptions {
688688
let expected = __map.cameraForCoordinates(
689689
for: coordinates.map { Coordinate2D(value: $0) },
690-
camera: CoreCameraOptions(camera),
690+
camera: CameraOptions.Marshaller.toObjc(camera),
691691
coordinatesPadding: coordinatesPadding?.toMBXEdgeInsetsValue(),
692692
maxZoom: maxZoom as? NSNumber,
693693
offset: offset?.screenCoordinate
@@ -699,7 +699,7 @@ public final class MapboxMap: StyleManager {
699699
guard let options = expected.value else {
700700
throw MapError(coreError: "Failed to unwrap CameraOptions")
701701
}
702-
return CameraOptions(options)
702+
return CameraOptions.Marshaller.toSwift(options)
703703
}
704704

705705
/// Calculates a `CameraOptions` to fit a geometry
@@ -744,7 +744,7 @@ public final class MapboxMap: StyleManager {
744744
padding: UIEdgeInsets,
745745
bearing: CGFloat?,
746746
pitch: CGFloat?) -> CameraOptions {
747-
return CameraOptions(
747+
return CameraOptions.Marshaller.toSwift(
748748
__map.cameraForGeometry(
749749
for: MapboxCommon.Geometry(geometry),
750750
padding: padding.toMBXEdgeInsetsValue(),
@@ -762,7 +762,7 @@ public final class MapboxMap: StyleManager {
762762
/// - Returns: `CoordinateBounds` for the given `CameraOptions`
763763
public func coordinateBounds(for camera: CameraOptions) -> CoordinateBounds {
764764
return __map.coordinateBoundsForCamera(
765-
forCamera: CoreCameraOptions(camera))
765+
forCamera: CameraOptions.Marshaller.toObjc(camera))
766766
}
767767

768768
/// Returns the unwrapped coordinate bounds to a given ``CameraOptions-swift.struct``.
@@ -774,7 +774,7 @@ public final class MapboxMap: StyleManager {
774774
/// - Parameter camera: The camera for which the coordinate bounds will be returned.
775775
/// - Returns: `CoordinateBounds` for the given ``CameraOptions-swift.struct``.
776776
public func coordinateBoundsUnwrapped(for camera: CameraOptions) -> CoordinateBounds {
777-
return __map.coordinateBoundsForCameraUnwrapped(forCamera: CoreCameraOptions(camera))
777+
return __map.coordinateBoundsForCameraUnwrapped(forCamera: CameraOptions.Marshaller.toObjc(camera))
778778
}
779779

780780
/// Returns the coordinate bounds and zoom for a given `CameraOptions`.
@@ -784,7 +784,7 @@ public final class MapboxMap: StyleManager {
784784
/// - Parameter camera: The camera for which the `CoordinateBoundsZoom` will be returned.
785785
/// - Returns: `CoordinateBoundsZoom` for the given `CameraOptions`
786786
public func coordinateBoundsZoom(for camera: CameraOptions) -> CoordinateBoundsZoom {
787-
return __map.coordinateBoundsZoomForCamera(forCamera: CoreCameraOptions(camera))
787+
return __map.coordinateBoundsZoomForCamera(forCamera: CameraOptions.Marshaller.toObjc(camera))
788788
}
789789

790790
/// Returns the unwrapped coordinate bounds and zoom for a given `CameraOptions`.
@@ -797,7 +797,7 @@ public final class MapboxMap: StyleManager {
797797
/// be returned.
798798
/// - Returns: `CoordinateBoundsZoom` for the given `CameraOptions`
799799
public func coordinateBoundsZoomUnwrapped(for camera: CameraOptions) -> CoordinateBoundsZoom {
800-
return __map.coordinateBoundsZoomForCameraUnwrapped(forCamera: CoreCameraOptions(camera))
800+
return __map.coordinateBoundsZoomForCameraUnwrapped(forCamera: CameraOptions.Marshaller.toObjc(camera))
801801
}
802802

803803
// MARK: - Screen coordinate conversion
@@ -897,12 +897,12 @@ public final class MapboxMap: StyleManager {
897897
///
898898
/// - Parameter cameraOptions: New camera options
899899
public func setCamera(to cameraOptions: CameraOptions) {
900-
__map.setCameraFor(CoreCameraOptions(cameraOptions))
900+
__map.setCameraFor(CameraOptions.Marshaller.toObjc(cameraOptions) as CoreCameraOptions)
901901
}
902902

903903
/// Returns the current camera state
904904
public var cameraState: CameraState {
905-
return CameraState(__map.getCameraState())
905+
CameraState.Marshaller.toSwift(__map.getCameraState())
906906
}
907907

908908
/// The map's current anchor, calculated after applying padding (if it exists)
@@ -960,7 +960,7 @@ public final class MapboxMap: StyleManager {
960960
/// The camera options object showing end point.
961961
public func dragCameraOptions(from: CGPoint, to: CGPoint) -> CameraOptions {
962962
let options = __map.cameraForDrag(forStart: from.screenCoordinate, end: to.screenCoordinate)
963-
return CameraOptions(options)
963+
return CameraOptions.Marshaller.toSwift(options)
964964
}
965965

966966
/// :nodoc:

0 commit comments

Comments
 (0)