Skip to content

Commit

Permalink
Minor refactoring; attempt to fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthetechie committed Mar 17, 2024
1 parent b7f55bb commit 742622d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 40 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
run: brew install swiftformat

- name: Checkout maplibre-swiftui-dsl-playground
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Check format
run: swiftformat . --lint
Expand All @@ -38,10 +38,10 @@ jobs:

- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '15.0'
xcode-version: '15.2'

- name: Checkout maplibre-swiftui-dsl-playground
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Test ${{ matrix.scheme }} on ${{ matrix.destination }}
run: xcodebuild -scheme ${{ matrix.scheme }} test -skipMacroValidation -destination '${{ matrix.destination }}' | xcbeautify && exit ${PIPESTATUS[0]}
78 changes: 41 additions & 37 deletions Sources/MapLibreSwiftUI/MapViewCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,50 +201,54 @@ extension MapViewCoordinator: MLNMapViewDelegate {
onStyleLoaded?(mglStyle)
}

/// The MapView's region has changed with a specific reason.
public func mapView(_ mapView: MLNMapView, regionDidChangeWith reason: MLNCameraChangeReason, animated _: Bool) {
guard !isUpdatingCamera else {
return
}

@MainActor private func updateParentCamera(mapView: MLNMapView, reason: MLNCameraChangeReason) {
// If any of these are a mismatch, we know the camera is no longer following a desired method, so we should
// detach and revert to a .centered camera. If any one of these is true, the desired camera state still
// matches the mapView's userTrackingMode
// NOTE: The use of assumeIsolated is just to make Swift strict concurrency checks happy.
// This invariant is upheld by the MLNMapView.
MainActor.assumeIsolated {
let userTrackingMode = mapView.userTrackingMode
let isProgrammaticallyTracking: Bool = switch parent.camera.state {
case .trackingUserLocation:
userTrackingMode == .follow
case .trackingUserLocationWithHeading:
userTrackingMode == .followWithHeading
case .trackingUserLocationWithCourse:
userTrackingMode == .followWithCourse
case .centered, .rect, .showcase:
false
}
let userTrackingMode = mapView.userTrackingMode
let isProgrammaticallyTracking: Bool = switch parent.camera.state {
case .trackingUserLocation:
userTrackingMode == .follow
case .trackingUserLocationWithHeading:
userTrackingMode == .followWithHeading
case .trackingUserLocationWithCourse:
userTrackingMode == .followWithCourse
case .centered, .rect, .showcase:
false
}

guard !isProgrammaticallyTracking else {
// Programmatic tracking is still active, we can ignore camera updates until we unset/fail this boolean
// check
return
}
guard !isProgrammaticallyTracking else {
// Programmatic tracking is still active, we can ignore camera updates until we unset/fail this boolean
// check
return
}

// Publish the MLNMapView's "raw" camera state to the MapView camera binding.
// This path only executes when the map view diverges from the parent state, so this is a "matter of fact"
// state propagation.
let newCamera: MapViewCamera = .center(mapView.centerCoordinate,
zoom: mapView.zoomLevel,
// TODO: Pitch doesn't really describe current state
pitch: .freeWithinRange(
minimum: mapView.minimumPitch,
maximum: mapView.maximumPitch
),
direction: mapView.direction,
reason: CameraChangeReason(reason))
snapshotCamera = newCamera
self.parent.camera = newCamera
}

/// The MapView's region has changed with a specific reason.
public func mapView(_ mapView: MLNMapView, regionDidChangeWith reason: MLNCameraChangeReason, animated _: Bool) {
guard !isUpdatingCamera else {
return
}

// Publish the MLNMapView's "raw" camera state to the MapView camera binding.
// This path only executes when the map view diverges from the parent state, so this is a "matter of fact"
// state propagation.
let newCamera: MapViewCamera = .center(mapView.centerCoordinate,
zoom: mapView.zoomLevel,
// TODO: Pitch doesn't really describe current state
pitch: .freeWithinRange(
minimum: mapView.minimumPitch,
maximum: mapView.maximumPitch
),
direction: mapView.direction,
reason: CameraChangeReason(reason))
snapshotCamera = newCamera
self.parent.camera = newCamera
MainActor.assumeIsolated {

Check failure on line 250 in Sources/MapLibreSwiftUI/MapViewCoordinator.swift

View workflow job for this annotation

GitHub Actions / test (MapLibreSwiftUI-Package, platform=iOS Simulator,name=iPhone 15,OS=17.2)

'assumeIsolated(_:file:line:)' is only available in iOS 17.0 or newer

Check failure on line 250 in Sources/MapLibreSwiftUI/MapViewCoordinator.swift

View workflow job for this annotation

GitHub Actions / test (MapLibreSwiftUI-Package, platform=iOS Simulator,name=iPhone 15,OS=17.2)

'assumeIsolated(_:file:line:)' is only available in iOS 17.0 or newer
updateParentCamera(mapView: mapView, reason: reason)
}
}
}

0 comments on commit 742622d

Please sign in to comment.