Skip to content

Commit 8635f1d

Browse files
committed
swiftfmt and bug fix
1 parent 742622d commit 8635f1d

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Sources/MapLibreSwiftUI/MapView.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ public struct MapView: UIViewRepresentable {
5252
mapView.delegate = context.coordinator
5353
context.coordinator.mapView = mapView
5454

55+
// Apply modifiers, suppressing camera update propagation (this messes with setting our initial camera as
56+
// content insets can trigger a change)
57+
context.coordinator.suppressCameraUpdatePropagation = true
5558
applyModifiers(mapView, runUnsafe: false)
59+
context.coordinator.suppressCameraUpdatePropagation = false
5660

5761
mapView.locationManager = locationManager
5862

Sources/MapLibreSwiftUI/MapViewCoordinator.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class MapViewCoordinator: NSObject {
1515
// Indicates whether we are currently in a push-down camera update cycle.
1616
// This is necessary in order to ensure we don't keep trying to reset a state value which we were already processing
1717
// an update for.
18-
private var isUpdatingCamera = false
18+
var suppressCameraUpdatePropagation = false
1919

2020
var onStyleLoaded: ((MLNStyle) -> Void)?
2121
var onGesture: (MLNMapView, UIGestureRecognizer) -> Void
@@ -53,7 +53,7 @@ public class MapViewCoordinator: NSObject {
5353
return
5454
}
5555

56-
isUpdatingCamera = true
56+
suppressCameraUpdatePropagation = true
5757
switch camera.state {
5858
case let .centered(onCoordinate: coordinate, zoom: zoom, pitch: pitch, direction: direction):
5959
mapView.userTrackingMode = .none
@@ -92,7 +92,7 @@ public class MapViewCoordinator: NSObject {
9292
}
9393

9494
snapshotCamera = camera
95-
isUpdatingCamera = false
95+
suppressCameraUpdatePropagation = false
9696
}
9797

9898
// MARK: - Coordinator API - Styles + Layers
@@ -238,12 +238,12 @@ extension MapViewCoordinator: MLNMapViewDelegate {
238238
direction: mapView.direction,
239239
reason: CameraChangeReason(reason))
240240
snapshotCamera = newCamera
241-
self.parent.camera = newCamera
241+
parent.camera = newCamera
242242
}
243243

244244
/// The MapView's region has changed with a specific reason.
245245
public func mapView(_ mapView: MLNMapView, regionDidChangeWith reason: MLNCameraChangeReason, animated _: Bool) {
246-
guard !isUpdatingCamera else {
246+
guard !suppressCameraUpdatePropagation else {
247247
return
248248
}
249249

0 commit comments

Comments
 (0)