implementing static location sheet

This commit is contained in:
Mauro Romito
2026-03-06 12:53:39 +01:00
committed by Mauro
parent 2b0771c43c
commit 4633b0b140
45 changed files with 447 additions and 258 deletions

View File

@@ -8,6 +8,7 @@
import CoreLocation
import Foundation
import MatrixRustSDK
enum LocationSharingViewError: Error, Hashable {
case missingAuthorization
@@ -21,25 +22,18 @@ enum LocationSharingScreenViewModelAction {
enum LocationSharingInteractionMode: Hashable {
case picker
case viewStatic(senderID: String?, geoURI: GeoURI)
var canShowAvatar: Bool {
switch self {
case .picker, .viewStatic(.some(_), _):
true
default:
false
}
}
case viewStatic(StaticLocationData)
}
struct LocationSharingScreenViewState: BindableState {
init(interactionMode: LocationSharingInteractionMode,
mapURLBuilder: MapTilerURLBuilderProtocol,
showLiveLocationSharingButton: Bool) {
showLiveLocationSharingButton: Bool,
ownUserID: String) {
self.interactionMode = interactionMode
self.mapURLBuilder = mapURLBuilder
self.showLiveLocationSharingButton = showLiveLocationSharingButton
self.ownUserID = ownUserID
bindings.showsUserLocationMode = switch interactionMode {
case .picker: .showAndFollow
@@ -50,6 +44,7 @@ struct LocationSharingScreenViewState: BindableState {
let interactionMode: LocationSharingInteractionMode
let mapURLBuilder: MapTilerURLBuilderProtocol
let showLiveLocationSharingButton: Bool
let ownUserID: String
var bindings = LocationSharingScreenBindings(showsUserLocationMode: .hide)
@@ -62,9 +57,9 @@ struct LocationSharingScreenViewState: BindableState {
switch interactionMode {
case .picker:
// middle point in Europe, to be used if the users location is not yet known
return .init(latitude: 49.843, longitude: 9.902056)
case .viewStatic(_, let geoURI):
return .init(latitude: geoURI.latitude, longitude: geoURI.longitude)
.init(latitude: 49.843, longitude: 9.902056)
case .viewStatic(let location):
.init(latitude: location.geoURI.latitude, longitude: location.geoURI.longitude)
}
}
@@ -76,15 +71,6 @@ struct LocationSharingScreenViewState: BindableState {
false
}
}
var showShareAction: Bool {
switch interactionMode {
case .picker:
return false
case .viewStatic:
return true
}
}
var isLocationLoading: Bool {
!bindings.hasLoadedUserLocation && bindings.isLocationAuthorized != false
@@ -105,12 +91,12 @@ struct LocationSharingScreenViewState: BindableState {
var userProfile: UserProfileProxy?
var shownUserProfile: UserProfileProxy? {
var staticLocationMarkerUserProfile: UserProfileProxy? {
switch interactionMode {
case .picker:
isSharingUserLocation ? userProfile : nil
case .viewStatic:
userProfile
case .viewStatic(let location):
location.kind == .sender ? userProfile : nil
}
}
}
@@ -172,3 +158,10 @@ extension AlertInfo where T == LocationSharingViewError {
}
}
}
struct StaticLocationData: Hashable {
let sender: TimelineItemSender
let geoURI: GeoURI
let kind: StaticLocationKind
let timestamp: Date
}