Show own location in map views (#7375)

* show own location on static sharing

* show own location on live sharing

* add tests and changelog

* check location authorisation, fix center to current user location button

* it moves request to LocationManager in proper service

* add static location viewer service
This commit is contained in:
Flescio
2023-02-20 18:07:03 +01:00
committed by GitHub
parent d15131e9ba
commit 95501bfdde
21 changed files with 267 additions and 36 deletions
@@ -34,23 +34,35 @@ struct LiveLocationSharingViewer: View {
@ObservedObject var viewModel: LiveLocationSharingViewerViewModel.Context
var mapView: LocationSharingMapView {
LocationSharingMapView(tileServerMapURL: viewModel.viewState.mapStyleURL,
annotations: viewModel.viewState.annotations,
highlightedAnnotation: viewModel.viewState.highlightedAnnotation,
userAvatarData: nil,
showsUserLocation: viewModel.viewState.showsUserLocation,
userAnnotationCanShowCallout: true,
userLocation: Binding.constant(nil),
mapCenterCoordinate: Binding.constant(nil),
onCalloutTap: { annotation in
if let userLocationAnnotation = annotation as? UserLocationAnnotation {
viewModel.send(viewAction: .share(userLocationAnnotation))
}
},
errorSubject: viewModel.viewState.errorSubject)
}
var body: some View {
ZStack(alignment: .bottom) {
if !viewModel.viewState.showMapLoadingError {
LocationSharingMapView(tileServerMapURL: viewModel.viewState.mapStyleURL,
annotations: viewModel.viewState.annotations,
highlightedAnnotation: viewModel.viewState.highlightedAnnotation,
userAvatarData: nil,
showsUserLocation: false,
userAnnotationCanShowCallout: true,
userLocation: Binding.constant(nil),
mapCenterCoordinate: Binding.constant(nil),
onCalloutTap: { annotation in
if let userLocationAnnotation = annotation as? UserLocationAnnotation {
viewModel.send(viewAction: .share(userLocationAnnotation))
}
},
errorSubject: viewModel.viewState.errorSubject)
if !viewModel.viewState.isCurrentUserShared {
mapView
.overlay(CenterToUserLocationButton(action: {
viewModel.send(viewAction: .showUserLocation)
}).offset(x: -11.0, y: 52), alignment: .topTrailing)
} else {
mapView
}
// Show map credits above collapsed bottom sheet height if bottom sheet is visible
if viewModel.viewState.isBottomSheetVisible {
@@ -178,3 +190,27 @@ struct LiveLocationSharingViewer_Previews: PreviewProvider {
}
}
}
struct CenterToUserLocationButton: View {
// MARK: Private
@Environment(\.theme) private var theme: ThemeSwiftUI
// MARK: Public
var action: () -> Void
var body: some View {
Button {
action()
} label: {
Image(uiImage: Asset.Images.locationCenterMapIcon.image)
.foregroundColor(theme.colors.accent)
}
.padding(8.0)
.background(theme.colors.background)
.clipShape(Circle())
.shadow(radius: 2.0)
}
}