From f23d6fe69a79cbffaace38c8298cd85db2a626bb Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Fri, 17 Apr 2026 16:29:59 +0200 Subject: [PATCH] fixed a bug that made the map still follow your location, even whan trying to center the map on an annotation. --- .../LocationSharingScreenModels.swift | 1 + .../LocationSharingScreenViewModel.swift | 3 +++ .../LocationSharing/View/LiveLocationSheet.swift | 6 ++++-- .../LocationSharing/View/StaticLocationSheet.swift | 13 +++++++------ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenModels.swift b/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenModels.swift index 7a7aae650..7265b4308 100644 --- a/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenModels.swift +++ b/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenModels.swift @@ -179,6 +179,7 @@ enum LocationSharingScreenViewAction { case centerToUser case userDidPan case stopLiveLocation + case setMapCenter(CLLocationCoordinate2D) } extension AlertInfo where T == LocationSharingViewAlert { diff --git a/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenViewModel.swift b/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenViewModel.swift index a5add685c..a4ef5fc70 100644 --- a/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenViewModel.swift +++ b/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenViewModel.swift @@ -85,6 +85,9 @@ class LocationSharingScreenViewModel: LocationSharingScreenViewModelType, Locati } case .stopLiveLocation: stopLiveLocation() + case .setMapCenter(let coordinate): + state.bindings.showsUserLocationMode = .show + state.bindings.mapCenterLocation = coordinate } } diff --git a/ElementX/Sources/Screens/LocationSharing/View/LiveLocationSheet.swift b/ElementX/Sources/Screens/LocationSharing/View/LiveLocationSheet.swift index 05d6849ba..90cacc56b 100644 --- a/ElementX/Sources/Screens/LocationSharing/View/LiveLocationSheet.swift +++ b/ElementX/Sources/Screens/LocationSharing/View/LiveLocationSheet.swift @@ -67,13 +67,15 @@ struct LiveLocationSheet: View { if let profile = context.viewState.userProfiles[liveLocationShare.userID] { Button { guard let geoURI = liveLocationShare.geoURI else { return } - context.mapCenterLocation = .init(latitude: geoURI.latitude, longitude: geoURI.longitude) + context.send(viewAction: .setMapCenter(.init(latitude: geoURI.latitude, longitude: geoURI.longitude))) } label: { UserLocationCell(profile: profile, isOwnUser: context.viewState.isOwnUser(liveLocationShare.userID), kind: .live, mediaProvider: context.mediaProvider, - onShare: { context.sharedAnnotation = context.viewState.annotations.first { $0.id == liveLocationShare.id }}, + onShare: { + context.sharedAnnotation = context.viewState.annotations.first { $0.id == liveLocationShare.id } + }, onStop: { context.send(viewAction: .stopLiveLocation) }) } } diff --git a/ElementX/Sources/Screens/LocationSharing/View/StaticLocationSheet.swift b/ElementX/Sources/Screens/LocationSharing/View/StaticLocationSheet.swift index 9b4d83751..fde8dacf3 100644 --- a/ElementX/Sources/Screens/LocationSharing/View/StaticLocationSheet.swift +++ b/ElementX/Sources/Screens/LocationSharing/View/StaticLocationSheet.swift @@ -37,8 +37,8 @@ struct StaticLocationSheet: View { if case let .viewStatic(location) = context.viewState.interactionMode, let profile = context.viewState.userProfiles.values.first { Button { - context.mapCenterLocation = .init(latitude: location.geoURI.latitude, - longitude: location.geoURI.longitude) + context.send(viewAction: .setMapCenter(.init(latitude: location.geoURI.latitude, + longitude: location.geoURI.longitude))) } label: { UserLocationCell(profile: profile, isOwnUser: context.viewState.isOwnUser(profile.userID), @@ -47,13 +47,14 @@ struct StaticLocationSheet: View { mediaProvider: context.mediaProvider, onShare: { context.sharedAnnotation = context.viewState.annotations.first - }) - } - .popover(item: $context.sharedAnnotation) { annotation in - LocationShareSheet(annotation: annotation) + }, + onStop: nil) } } } + .popover(item: $context.sharedAnnotation) { annotation in + LocationShareSheet(annotation: annotation) + } } }