Skip to content

Commit

Permalink
Fix integration tests getting stuck in location error loop. (#2233)
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave authored Dec 13, 2023
1 parent d99d26f commit e328863
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
26 changes: 15 additions & 11 deletions ElementX/Sources/Other/MapLibre/MapLibreMapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,12 @@ struct MapLibreMapView: UIViewRepresentable {

/// Behavior mode of the current user's location, can be hidden, only shown and shown following the user
@Binding var showsUserLocationMode: ShowUserLocationMode

/// Bind view errors if any
@Binding var error: MapLibreError?

/// Coordinate of the center of the map
@Binding var mapCenterCoordinate: CLLocationCoordinate2D?

@Binding var isLocationAuthorized: Bool?

// The radius of uncertainty for the location, measured in meters.
/// The radius of uncertainty for the location, measured in meters.
@Binding var geolocationUncertainty: CLLocationAccuracy?

/// Called when the user pan on the map
Expand All @@ -74,7 +70,14 @@ struct MapLibreMapView: UIViewRepresentable {
}

func updateUIView(_ mapView: MGLMapView, context: Context) {
mapView.styleURL = builder.dynamicMapURL(for: .init(colorScheme))
// Don't set the same value twice. Otherwise, if there is an error loading the map, a loop
// is caused as the `error` binding being set, which triggers this update, which sets a
// new URL, which causes another error, and so it goes on round and round in a circle.
let dynamicMapURL = builder.dynamicMapURL(for: .init(colorScheme))
if mapView.styleURL != dynamicMapURL {
mapView.styleURL = dynamicMapURL
}

showUserLocation(in: mapView)
}

Expand Down Expand Up @@ -106,10 +109,9 @@ struct MapLibreMapView: UIViewRepresentable {
case (.showAndFollow, _):
mapView.userTrackingMode = .follow
case (.show, let annotations) where !annotations.isEmpty:
/** in the show mode, if there are annotations, we check the authorizationStatus,
if it's not determined, we wont prompt the user with a request for permissions,
because he should be able to see the annotations without sharing his location informations
**/
// In the show mode, if there are annotations, we check the authorizationStatus,
// if it's not determined, we wont prompt the user with a request for permissions,
// because they should be able to see the annotations without sharing their location information.
guard mapView.locationManager.authorizationStatus != .notDetermined else { return }
fallthrough
case (.show, _):
Expand Down Expand Up @@ -148,7 +150,9 @@ extension MapLibreMapView {
}

func mapViewDidFailLoadingMap(_ mapView: MGLMapView, withError error: Error) {
mapLibreView.error = .failedLoadingMap
if mapLibreView.error != .failedLoadingMap {
mapLibreView.error = .failedLoadingMap
}
}

func mapView(_ mapView: MGLMapView, didUpdate userLocation: MGLUserLocation?) {
Expand Down
1 change: 1 addition & 0 deletions changelog.d/pr-2233.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Don't keep throwing an error each time the user dismisses the error's alert when sharing a location.

0 comments on commit e328863

Please sign in to comment.