From 8635f1deba73b48839480b28bc6ceb30029478a3 Mon Sep 17 00:00:00 2001 From: Ian Wagner Date: Mon, 18 Mar 2024 03:10:06 +0900 Subject: [PATCH] swiftfmt and bug fix --- Sources/MapLibreSwiftUI/MapView.swift | 4 ++++ Sources/MapLibreSwiftUI/MapViewCoordinator.swift | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Sources/MapLibreSwiftUI/MapView.swift b/Sources/MapLibreSwiftUI/MapView.swift index 44f92ae..5b10d9e 100644 --- a/Sources/MapLibreSwiftUI/MapView.swift +++ b/Sources/MapLibreSwiftUI/MapView.swift @@ -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 diff --git a/Sources/MapLibreSwiftUI/MapViewCoordinator.swift b/Sources/MapLibreSwiftUI/MapViewCoordinator.swift index 20e3489..7c92933 100644 --- a/Sources/MapLibreSwiftUI/MapViewCoordinator.swift +++ b/Sources/MapLibreSwiftUI/MapViewCoordinator.swift @@ -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 @@ -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 @@ -92,7 +92,7 @@ public class MapViewCoordinator: NSObject { } snapshotCamera = camera - isUpdatingCamera = false + suppressCameraUpdatePropagation = false } // MARK: - Coordinator API - Styles + Layers @@ -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 }