LocationSharingScreen: fix indefinite loading on the center to location button in non picker mode (#5469)

This commit is contained in:
Mauro
2026-04-22 18:36:15 +02:00
committed by GitHub
parent b1d82add91
commit 36fd7b2660
15 changed files with 101 additions and 18 deletions

View File

@@ -117,10 +117,18 @@ struct LocationSharingScreenViewState: BindableState {
}
}
/// Returns true if the user's location has not yet been determined, while location permissions are given or not yet set
/// Displays a loader if the user's location has not yet been determined
/// Does not work as intended on simulator.
var isLocationLoading: Bool {
!bindings.hasLoadedUserLocation && bindings.isLocationAuthorized != false
if case .picker = interactionMode {
// In picker mode permissions are requested immediately so returns true
// if the user's location has not yet been determined while location permissions are given or not yet set
!bindings.hasLoadedUserLocation && bindings.isLocationAuthorized != false
} else {
// In other modes permissions are requested only if the center to user button is tapped
// So we only display the loader if the user's location has not yet been determined while location permissions are given.
!bindings.hasLoadedUserLocation && bindings.isLocationAuthorized == true
}
}
var zoomLevel: Double {

View File

@@ -133,6 +133,8 @@ struct LocationSharingScreen_Previews: PreviewProvider, TestablePreview {
static let pickerViewModel = LocationSharingScreenViewModel.mock(type: .picker)
static let liveLocationViewModel = LocationSharingScreenViewModel.mock(type: .viewLive)
static var previews: some View {
ElementNavigationStack {
LocationSharingScreen(context: pickerViewModel.context)
@@ -153,5 +155,10 @@ struct LocationSharingScreen_Previews: PreviewProvider, TestablePreview {
LocationSharingScreen(context: pinViewModel.context)
}
.previewDisplayName("Pin Static Location")
ElementNavigationStack {
LocationSharingScreen(context: liveLocationViewModel.context)
}
.previewDisplayName("Live Location")
}
}

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ebe9ad381e752245ac59cd33c9cdbdc813dad50e923c0bfd262bb920c93aad74
size 91241

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ebe9ad381e752245ac59cd33c9cdbdc813dad50e923c0bfd262bb920c93aad74
size 91241

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:4e79d367b72ad8c487aed8d31dc57c496e7b6ba68ee9474cffbb4ad08f18b26b
size 49018

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:4e79d367b72ad8c487aed8d31dc57c496e7b6ba68ee9474cffbb4ad08f18b26b
size 49018

View File

@@ -124,6 +124,62 @@ final class LocationSharingScreenViewModelTests {
}
}
// MARK: - isLocationLoading Tests
@Test
func isLocationLoadingInPickerModeWithAuthorizationNotDetermined() {
setupViewModel()
context.isLocationAuthorized = nil
context.hasLoadedUserLocation = false
#expect(context.viewState.isLocationLoading)
}
@Test
func isLocationLoadingInPickerModeWithAuthorizationGranted() {
setupViewModel()
context.isLocationAuthorized = true
context.hasLoadedUserLocation = false
#expect(context.viewState.isLocationLoading)
}
@Test
func isLocationNotLoadingInPickerModeWhenLocationLoaded() {
setupViewModel()
context.isLocationAuthorized = true
context.hasLoadedUserLocation = true
#expect(!context.viewState.isLocationLoading)
}
@Test
func isLocationNotLoadingInPickerModeWhenAuthorizationDenied() {
setupViewModel()
context.isLocationAuthorized = false
context.hasLoadedUserLocation = false
#expect(!context.viewState.isLocationLoading)
}
@Test
func isLocationNotLoadingInNonPickerModeWithAuthorizationNotDetermined() {
let aliceShare = makeLiveLocationShare(userID: "@alice:matrix.org")
let sender = TimelineItemSender(id: "@alice:matrix.org", displayName: "Alice")
let liveLocationsSubject = CurrentValueSubject<[LiveLocationShare], Never>([aliceShare])
setupViewModelForViewLive(sender: sender, initialShare: aliceShare, liveLocationsSubject: liveLocationsSubject)
context.isLocationAuthorized = nil
context.hasLoadedUserLocation = false
#expect(!context.viewState.isLocationLoading)
}
@Test
func isLocationLoadingInNonPickerModeWithAuthorizationGiven() {
let aliceShare = makeLiveLocationShare(userID: "@alice:matrix.org")
let sender = TimelineItemSender(id: "@alice:matrix.org", displayName: "Alice")
let liveLocationsSubject = CurrentValueSubject<[LiveLocationShare], Never>([aliceShare])
setupViewModelForViewLive(sender: sender, initialShare: aliceShare, liveLocationsSubject: liveLocationsSubject)
context.isLocationAuthorized = true
context.hasLoadedUserLocation = false
#expect(context.viewState.isLocationLoading)
}
// MARK: - Live Location Authorization Tests
@Test