diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2023-01-30 15:10:05 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2023-01-30 15:10:05 +0100 |
| commit | e80c8c55b3133a85cf3cf8f95600b54acacd0f8f (patch) | |
| tree | 185fd42239b17b4922f444d7d68d274a46e746f6 | |
| parent | eb91ae2f3609841def5735c5a837d1bbd3f3fd10 (diff) | |
| parent | 088bedb8208c295c2ddab5b248edc0bf1ce22862 (diff) | |
| download | mullvadvpn-e80c8c55b3133a85cf3cf8f95600b54acacd0f8f.tar.xz mullvadvpn-e80c8c55b3133a85cf3cf8f95600b54acacd0f8f.zip | |
Merge branch 'map-invalid-argument-ex'
| -rw-r--r-- | ios/MullvadVPN/MapViewController.swift | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/ios/MullvadVPN/MapViewController.swift b/ios/MullvadVPN/MapViewController.swift index 2ea933d9ef..9a8a434dd3 100644 --- a/ios/MullvadVPN/MapViewController.swift +++ b/ios/MullvadVPN/MapViewController.swift @@ -22,7 +22,7 @@ final class MapViewController: UIViewController, MKMapViewDelegate { private var willChangeRegion = false private var regionDidChangeCompletion: (() -> Void)? private let mapView = MKMapView() - + private var isFirstLayoutPass = true private var center: CLLocationCoordinate2D? var alignmentView: UIView? @@ -62,6 +62,15 @@ final class MapViewController: UIViewController, MKMapViewDelegate { }) } + override func viewDidLayoutSubviews() { + super.viewDidLayoutSubviews() + + if isFirstLayoutPass { + isFirstLayoutPass = false + recomputeVisibleRegion(animated: false) + } + } + // MARK: - Public func addLocationMarker(coordinate: CLLocationCoordinate2D) { @@ -179,13 +188,6 @@ final class MapViewController: UIViewController, MKMapViewDelegate { self.center = center - logger.debug( - """ - Set map region to: (\(region.center.latitude), \(region.center.longitude), \ - \(region.span.latitudeDelta), \(region.span.longitudeDelta)) - """ - ) - // Map view does not call delegate methods when attempting to set the same region. mapView.setRegion(region, animated: animated) @@ -254,7 +256,10 @@ final class MapViewController: UIViewController, MKMapViewDelegate { ) -> MKCoordinateRegion { // Map view center lies within layout margins frame. let mapViewLayoutFrame = mapView.layoutMarginsGuide.layoutFrame - guard mapViewLayoutFrame.width > 0 else { return region } + + guard mapViewLayoutFrame.width > 0, mapView.frame.width > 0, + region.span.longitudeDelta > 0, + mapView.region.span.longitudeDelta > 0 else { return region } // MKMapView.convert(_:toRectTo:) returns CGRect scaled to the zoom level derived from // currently set region. @@ -272,6 +277,10 @@ final class MapViewController: UIViewController, MKMapViewDelegate { let offsetRegionRect = regionRect.offsetBy(dx: horizontalOffset, dy: verticalOffset) let offsetRegion = mapView.convert(offsetRegionRect, toRegionFrom: mapView) - return offsetRegion + if CLLocationCoordinate2DIsValid(offsetRegion.center) { + return offsetRegion + } else { + return region + } } } |
