@@ -201,50 +201,54 @@ extension MapViewCoordinator: MLNMapViewDelegate {
201201 onStyleLoaded ? ( mglStyle)
202202 }
203203
204- /// The MapView's region has changed with a specific reason.
205- public func mapView( _ mapView: MLNMapView , regionDidChangeWith reason: MLNCameraChangeReason , animated _: Bool ) {
206- guard !isUpdatingCamera else {
207- return
208- }
209-
204+ @MainActor private func updateParentCamera( mapView: MLNMapView , reason: MLNCameraChangeReason ) {
210205 // If any of these are a mismatch, we know the camera is no longer following a desired method, so we should
211206 // detach and revert to a .centered camera. If any one of these is true, the desired camera state still
212207 // matches the mapView's userTrackingMode
213208 // NOTE: The use of assumeIsolated is just to make Swift strict concurrency checks happy.
214209 // This invariant is upheld by the MLNMapView.
215- MainActor . assumeIsolated {
216- let userTrackingMode = mapView. userTrackingMode
217- let isProgrammaticallyTracking : Bool = switch parent. camera. state {
218- case . trackingUserLocation:
219- userTrackingMode == . follow
220- case . trackingUserLocationWithHeading:
221- userTrackingMode == . followWithHeading
222- case . trackingUserLocationWithCourse:
223- userTrackingMode == . followWithCourse
224- case . centered, . rect, . showcase:
225- false
226- }
210+ let userTrackingMode = mapView. userTrackingMode
211+ let isProgrammaticallyTracking : Bool = switch parent. camera. state {
212+ case . trackingUserLocation:
213+ userTrackingMode == . follow
214+ case . trackingUserLocationWithHeading:
215+ userTrackingMode == . followWithHeading
216+ case . trackingUserLocationWithCourse:
217+ userTrackingMode == . followWithCourse
218+ case . centered, . rect, . showcase:
219+ false
220+ }
227221
228- guard !isProgrammaticallyTracking else {
229- // Programmatic tracking is still active, we can ignore camera updates until we unset/fail this boolean
230- // check
231- return
232- }
222+ guard !isProgrammaticallyTracking else {
223+ // Programmatic tracking is still active, we can ignore camera updates until we unset/fail this boolean
224+ // check
225+ return
226+ }
227+
228+ // Publish the MLNMapView's "raw" camera state to the MapView camera binding.
229+ // This path only executes when the map view diverges from the parent state, so this is a "matter of fact"
230+ // state propagation.
231+ let newCamera : MapViewCamera = . center( mapView. centerCoordinate,
232+ zoom: mapView. zoomLevel,
233+ // TODO: Pitch doesn't really describe current state
234+ pitch: . freeWithinRange(
235+ minimum: mapView. minimumPitch,
236+ maximum: mapView. maximumPitch
237+ ) ,
238+ direction: mapView. direction,
239+ reason: CameraChangeReason ( reason) )
240+ snapshotCamera = newCamera
241+ self . parent. camera = newCamera
242+ }
243+
244+ /// The MapView's region has changed with a specific reason.
245+ public func mapView( _ mapView: MLNMapView , regionDidChangeWith reason: MLNCameraChangeReason , animated _: Bool ) {
246+ guard !isUpdatingCamera else {
247+ return
248+ }
233249
234- // Publish the MLNMapView's "raw" camera state to the MapView camera binding.
235- // This path only executes when the map view diverges from the parent state, so this is a "matter of fact"
236- // state propagation.
237- let newCamera : MapViewCamera = . center( mapView. centerCoordinate,
238- zoom: mapView. zoomLevel,
239- // TODO: Pitch doesn't really describe current state
240- pitch: . freeWithinRange(
241- minimum: mapView. minimumPitch,
242- maximum: mapView. maximumPitch
243- ) ,
244- direction: mapView. direction,
245- reason: CameraChangeReason ( reason) )
246- snapshotCamera = newCamera
247- self . parent. camera = newCamera
250+ MainActor . assumeIsolated {
251+ updateParentCamera ( mapView: mapView, reason: reason)
248252 }
249253 }
250254}
0 commit comments