Skip to content

Commit 742622d

Browse files
committed
Minor refactoring; attempt to fix CI
1 parent b7f55bb commit 742622d

File tree

2 files changed

+44
-40
lines changed

2 files changed

+44
-40
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
run: brew install swiftformat
1616

1717
- name: Checkout maplibre-swiftui-dsl-playground
18-
uses: actions/checkout@v3
18+
uses: actions/checkout@v4
1919

2020
- name: Check format
2121
run: swiftformat . --lint
@@ -38,10 +38,10 @@ jobs:
3838

3939
- uses: maxim-lobanov/setup-xcode@v1
4040
with:
41-
xcode-version: '15.0'
41+
xcode-version: '15.2'
4242

4343
- name: Checkout maplibre-swiftui-dsl-playground
44-
uses: actions/checkout@v3
44+
uses: actions/checkout@v4
4545

4646
- name: Test ${{ matrix.scheme }} on ${{ matrix.destination }}
4747
run: xcodebuild -scheme ${{ matrix.scheme }} test -skipMacroValidation -destination '${{ matrix.destination }}' | xcbeautify && exit ${PIPESTATUS[0]}

Sources/MapLibreSwiftUI/MapViewCoordinator.swift

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)