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
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"originHash" : "e5123889438e3e8a4097dfcd17eaffeef3252f808a02de32d517dd5e9c8ead14",
2+
"originHash" : "3ef0341fce60ebda3bd350b1bafb9cebcd8654136f438ae028750da294ee7bf8",
33
"pins" : [
44
{
55
"identity" : "maplibre-gl-native-distribution",
@@ -19,6 +19,15 @@
1919
"version" : "0.3.1"
2020
}
2121
},
22+
{
23+
"identity" : "swift-custom-dump",
24+
"kind" : "remoteSourceControl",
25+
"location" : "https://github.com/pointfreeco/swift-custom-dump",
26+
"state" : {
27+
"revision" : "82645ec760917961cfa08c9c0c7104a57a0fa4b1",
28+
"version" : "1.3.3"
29+
}
30+
},
2231
{
2332
"identity" : "swift-macro-testing",
2433
"kind" : "remoteSourceControl",
@@ -33,8 +42,8 @@
3342
"kind" : "remoteSourceControl",
3443
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
3544
"state" : {
36-
"revision" : "2e6a85b73fc14e27d7542165ae73b1a10516ca9a",
37-
"version" : "1.17.7"
45+
"revision" : "1be8144023c367c5de701a6313ed29a3a10bf59b",
46+
"version" : "1.18.3"
3847
}
3948
},
4049
{

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)