Skip to content

Commit 579c378

Browse files
Fix/camera state stalls (#84)
* feat: task based camera * fix: modern concurrency camera * fix: modern concurrency camera * Update MapViewCoordinatorCameraTests.swift Co-authored-by: Ian Wagner <[email protected]> * Correcting task sleep * Adds docs, reverts structure for private * Adds docs, reverts structure for private --------- Co-authored-by: Ian Wagner <[email protected]>
1 parent 4a8fc8a commit 579c378

File tree

7 files changed

+396
-284
lines changed

7 files changed

+396
-284
lines changed

Package.resolved

Lines changed: 12 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/MapLibreSwiftUI/Extensions/MapLibre/MLNMapViewCameraUpdating.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public protocol MLNMapViewCameraUpdating: AnyObject {
99
@MainActor var userTrackingMode: MLNUserTrackingMode { get set }
1010
@MainActor func setUserTrackingMode(_ mode: MLNUserTrackingMode, animated: Bool, completionHandler: (() -> Void)?)
1111

12+
@MainActor var centerCoordinate: CLLocationCoordinate2D { get set }
13+
@MainActor var zoomLevel: Double { get set }
1214
@MainActor var minimumPitch: CGFloat { get set }
1315
@MainActor var maximumPitch: CGFloat { get set }
1416
@MainActor var direction: CLLocationDirection { get set }

Sources/MapLibreSwiftUI/MapView.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ public struct MapView<T: MapViewHostViewController>: UIViewControllerRepresentab
7676

7777
// Apply modifiers, suppressing camera update propagation (this messes with setting our initial camera as
7878
// content insets can trigger a change)
79-
context.coordinator.suppressCameraUpdatePropagation = true
8079
applyModifiers(controller, runUnsafe: false)
81-
context.coordinator.suppressCameraUpdatePropagation = false
8280

8381
controller.mapView.locationManager = locationManager
8482

@@ -87,9 +85,12 @@ public struct MapView<T: MapViewHostViewController>: UIViewControllerRepresentab
8785
controller.mapView.styleURL = styleURL
8886
}
8987

90-
context.coordinator.updateCamera(mapView: controller.mapView,
91-
camera: $camera.wrappedValue,
92-
animated: false)
88+
context.coordinator.applyCameraChangeFromStateUpdate(
89+
controller.mapView,
90+
camera: camera,
91+
animated: false
92+
)
93+
9394
controller.mapView.locationManager = controller.mapView.locationManager
9495

9596
// Link the style loaded to the coordinator that emits the delegate event.
@@ -116,9 +117,11 @@ public struct MapView<T: MapViewHostViewController>: UIViewControllerRepresentab
116117
let isStyleLoaded = uiViewController.mapView.style != nil
117118

118119
if cameraDisabled == false {
119-
context.coordinator.updateCamera(mapView: uiViewController.mapView,
120-
camera: camera,
121-
animated: isStyleLoaded)
120+
context.coordinator.applyCameraChangeFromStateUpdate(
121+
uiViewController.mapView,
122+
camera: camera,
123+
animated: isStyleLoaded
124+
)
122125
}
123126
}
124127

0 commit comments

Comments
 (0)