Skip to content

Commit

Permalink
swiftfmt and bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthetechie committed Mar 17, 2024
1 parent 742622d commit 8635f1d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Sources/MapLibreSwiftUI/MapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ public struct MapView: UIViewRepresentable {
mapView.delegate = context.coordinator
context.coordinator.mapView = mapView

// Apply modifiers, suppressing camera update propagation (this messes with setting our initial camera as
// content insets can trigger a change)
context.coordinator.suppressCameraUpdatePropagation = true
applyModifiers(mapView, runUnsafe: false)
context.coordinator.suppressCameraUpdatePropagation = false

mapView.locationManager = locationManager

Expand Down
10 changes: 5 additions & 5 deletions Sources/MapLibreSwiftUI/MapViewCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class MapViewCoordinator: NSObject {
// Indicates whether we are currently in a push-down camera update cycle.
// This is necessary in order to ensure we don't keep trying to reset a state value which we were already processing
// an update for.
private var isUpdatingCamera = false
var suppressCameraUpdatePropagation = false

var onStyleLoaded: ((MLNStyle) -> Void)?
var onGesture: (MLNMapView, UIGestureRecognizer) -> Void
Expand Down Expand Up @@ -53,7 +53,7 @@ public class MapViewCoordinator: NSObject {
return
}

isUpdatingCamera = true
suppressCameraUpdatePropagation = true
switch camera.state {
case let .centered(onCoordinate: coordinate, zoom: zoom, pitch: pitch, direction: direction):
mapView.userTrackingMode = .none
Expand Down Expand Up @@ -92,7 +92,7 @@ public class MapViewCoordinator: NSObject {
}

snapshotCamera = camera
isUpdatingCamera = false
suppressCameraUpdatePropagation = false
}

// MARK: - Coordinator API - Styles + Layers
Expand Down Expand Up @@ -238,12 +238,12 @@ extension MapViewCoordinator: MLNMapViewDelegate {
direction: mapView.direction,
reason: CameraChangeReason(reason))
snapshotCamera = newCamera
self.parent.camera = newCamera
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 {
guard !suppressCameraUpdatePropagation else {
return
}

Expand Down

0 comments on commit 8635f1d

Please sign in to comment.