Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix integration tests getting stuck in location error loop. #2233

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.