mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-23 18:12:44 +02:00
Merge branch 'develop' into steve/5903_lls_start
# Conflicts: # Riot/Modules/Room/RoomViewController.h # RiotSwiftUI/Modules/Room/LocationSharing/Coordinator/LocationSharingCoordinator.swift # RiotSwiftUI/Modules/Room/LocationSharing/LocationSharingModels.swift # RiotSwiftUI/Modules/Room/LocationSharing/LocationSharingViewModel.swift
This commit is contained in:
@@ -33,10 +33,10 @@ struct LocationSharingMapView: UIViewRepresentable {
|
||||
let tileServerMapURL: URL
|
||||
|
||||
/// Map annotations
|
||||
let annotations: [UserLocationAnnotation]
|
||||
let annotations: [LocationAnnotation]
|
||||
|
||||
/// Map annotation to focus on
|
||||
let highlightedAnnotation: UserLocationAnnotation?
|
||||
let highlightedAnnotation: LocationAnnotation?
|
||||
|
||||
/// Current user avatar data, used to replace current location annotation view with the user avatar
|
||||
let userAvatarData: AvatarInputProtocol?
|
||||
@@ -47,6 +47,9 @@ struct LocationSharingMapView: UIViewRepresentable {
|
||||
/// Last user location if `showsUserLocation` has been enabled
|
||||
@Binding var userLocation: CLLocationCoordinate2D?
|
||||
|
||||
/// Coordinate of the center of the map
|
||||
@Binding var mapCenterCoordinate: CLLocationCoordinate2D?
|
||||
|
||||
/// Publish view errors if any
|
||||
let errorSubject: PassthroughSubject<LocationSharingViewError, Never>
|
||||
|
||||
@@ -68,7 +71,7 @@ struct LocationSharingMapView: UIViewRepresentable {
|
||||
mapView.setCenter(highlightedAnnotation.coordinate, zoomLevel: Constants.mapZoomLevel, animated: false)
|
||||
}
|
||||
|
||||
if self.showsUserLocation {
|
||||
if self.showsUserLocation && mapCenterCoordinate == nil {
|
||||
mapView.showsUserLocation = true
|
||||
mapView.userTrackingMode = .follow
|
||||
} else {
|
||||
@@ -114,10 +117,12 @@ extension LocationSharingMapView {
|
||||
func mapView(_ mapView: MGLMapView, viewFor annotation: MGLAnnotation) -> MGLAnnotationView? {
|
||||
|
||||
if let userLocationAnnotation = annotation as? UserLocationAnnotation {
|
||||
return UserLocationAnnotatonView(userLocationAnnotation: userLocationAnnotation)
|
||||
} else if annotation is MGLUserLocation, let currentUserAvatarData = locationSharingMapView.userAvatarData {
|
||||
// Replace default current location annotation view with a UserLocationAnnotatonView
|
||||
return UserLocationAnnotatonView(avatarData: currentUserAvatarData)
|
||||
return LocationAnnotatonView(userLocationAnnotation: userLocationAnnotation)
|
||||
} else if let pinLocationAnnotation = annotation as? PinLocationAnnotation {
|
||||
return LocationAnnotatonView(pinLocationAnnotation: pinLocationAnnotation)
|
||||
} else if annotation is MGLUserLocation && locationSharingMapView.mapCenterCoordinate == nil, let currentUserAvatarData = locationSharingMapView.userAvatarData {
|
||||
// Replace default current location annotation view with a UserLocationAnnotatonView when the map is center on user location
|
||||
return LocationAnnotatonView(avatarData: currentUserAvatarData)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -145,6 +150,16 @@ extension LocationSharingMapView {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
func mapView(_ mapView: MGLMapView, regionDidChangeAnimated animated: Bool) {
|
||||
let mapCenterCoordinate = mapView.centerCoordinate
|
||||
// Prevent this function to set pinLocation when the map is openning
|
||||
guard let userLocation = locationSharingMapView.userLocation,
|
||||
!userLocation.isEqual(to: mapCenterCoordinate, precision: 0.0000000001) else {
|
||||
return
|
||||
}
|
||||
locationSharingMapView.mapCenterCoordinate = mapCenterCoordinate
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ struct LocationSharingMarkerView<Content: View>: View {
|
||||
markerImage
|
||||
.frame(width: 40, height: 40)
|
||||
}
|
||||
.offset(x: 0, y: -23)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,13 +33,7 @@ struct LocationSharingView: View {
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
ZStack(alignment: .bottom) {
|
||||
LocationSharingMapView(tileServerMapURL: context.viewState.mapStyleURL,
|
||||
annotations: context.viewState.annotations,
|
||||
highlightedAnnotation: context.viewState.highlightedAnnotation,
|
||||
userAvatarData: context.viewState.userAvatarData,
|
||||
showsUserLocation: context.viewState.showsUserLocation,
|
||||
userLocation: $context.userLocation,
|
||||
errorSubject: context.viewState.errorSubject)
|
||||
mapView
|
||||
VStack(spacing: 0) {
|
||||
MapCreditsView()
|
||||
if context.viewState.shareButtonVisible {
|
||||
@@ -85,6 +79,39 @@ struct LocationSharingView: View {
|
||||
.navigationViewStyle(StackNavigationViewStyle())
|
||||
}
|
||||
|
||||
var mapView: some View {
|
||||
ZStack(alignment: .topTrailing) {
|
||||
ZStack(alignment: .center) {
|
||||
LocationSharingMapView(tileServerMapURL: context.viewState.mapStyleURL,
|
||||
annotations: context.viewState.annotations,
|
||||
highlightedAnnotation: context.viewState.highlightedAnnotation,
|
||||
userAvatarData: context.viewState.userAvatarData,
|
||||
showsUserLocation: context.viewState.showsUserLocation,
|
||||
userLocation: $context.userLocation,
|
||||
mapCenterCoordinate: $context.pinLocation,
|
||||
errorSubject: context.viewState.errorSubject)
|
||||
if context.viewState.isPinDropSharing {
|
||||
LocationSharingMarkerView(backgroundColor: theme.colors.accent) {
|
||||
Image(uiImage: Asset.Images.locationPinIcon.image)
|
||||
.resizable()
|
||||
.shapedBorder(color: theme.colors.accent, borderWidth: 3, shape: Circle())
|
||||
}
|
||||
}
|
||||
}
|
||||
Button {
|
||||
context.send(viewAction: .goToUserLocation)
|
||||
} label: {
|
||||
Image(uiImage: Asset.Images.locationCenterMapIcon.image)
|
||||
.foregroundColor(theme.colors.accent)
|
||||
}
|
||||
.padding(6.0)
|
||||
.background(theme.colors.background)
|
||||
.clipShape(RoundedCornerShape(radius: 4, corners: [.allCorners]))
|
||||
.shadow(radius: 2.0)
|
||||
.offset(x: -11.0, y: 52)
|
||||
}
|
||||
}
|
||||
|
||||
var buttonsView: some View {
|
||||
VStack(alignment: .leading, spacing: 15) {
|
||||
if !context.viewState.isPinDropSharing {
|
||||
@@ -107,7 +134,7 @@ struct LocationSharingView: View {
|
||||
}
|
||||
} else {
|
||||
LocationSharingOptionButton(text: VectorL10n.locationSharingPinDropShareTitle) {
|
||||
// TODO: - Pin drop sharing action
|
||||
context.send(viewAction: .sharePinLocation)
|
||||
} buttonIcon: {
|
||||
Image(uiImage: Asset.Images.locationPinIcon.image)
|
||||
.resizable()
|
||||
|
||||
@@ -19,7 +19,7 @@ import SwiftUI
|
||||
import Mapbox
|
||||
|
||||
@available(iOS 14, *)
|
||||
class UserLocationAnnotatonView: MGLUserLocationAnnotationView {
|
||||
class LocationAnnotatonView: MGLUserLocationAnnotationView {
|
||||
|
||||
// MARK: Private
|
||||
|
||||
@@ -39,6 +39,14 @@ class UserLocationAnnotatonView: MGLUserLocationAnnotationView {
|
||||
super.init(annotation: userLocationAnnotation, reuseIdentifier: nil)
|
||||
|
||||
self.addUserMarkerView(with: userLocationAnnotation.avatarData)
|
||||
|
||||
}
|
||||
|
||||
init(pinLocationAnnotation: PinLocationAnnotation) {
|
||||
// TODO: Use a reuseIdentifier
|
||||
super.init(annotation: pinLocationAnnotation, reuseIdentifier: nil)
|
||||
|
||||
self.addPinMarkerView()
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
@@ -55,12 +63,26 @@ class UserLocationAnnotatonView: MGLUserLocationAnnotationView {
|
||||
}).view else {
|
||||
return
|
||||
}
|
||||
addMarkerView(with: avatarImageView)
|
||||
}
|
||||
|
||||
private func addPinMarkerView() {
|
||||
guard let pinImageView = UIHostingController(rootView: LocationSharingMarkerView(backgroundColor: theme.colors.accent) {
|
||||
Image(uiImage: Asset.Images.locationPinIcon.image)
|
||||
.resizable()
|
||||
.shapedBorder(color: theme.colors.accent, borderWidth: 3, shape: Circle())
|
||||
}).view else {
|
||||
return
|
||||
}
|
||||
addMarkerView(with: pinImageView)
|
||||
}
|
||||
|
||||
private func addMarkerView(with imageView: UIView) {
|
||||
addSubview(imageView)
|
||||
|
||||
addSubview(avatarImageView)
|
||||
|
||||
addConstraints([topAnchor.constraint(equalTo: avatarImageView.topAnchor),
|
||||
leadingAnchor.constraint(equalTo: avatarImageView.leadingAnchor),
|
||||
bottomAnchor.constraint(equalTo: avatarImageView.bottomAnchor),
|
||||
trailingAnchor.constraint(equalTo: avatarImageView.trailingAnchor)])
|
||||
addConstraints([topAnchor.constraint(equalTo: imageView.topAnchor),
|
||||
leadingAnchor.constraint(equalTo: imageView.leadingAnchor),
|
||||
bottomAnchor.constraint(equalTo: imageView.bottomAnchor),
|
||||
trailingAnchor.constraint(equalTo: imageView.trailingAnchor)])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user