mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-29 07:42:40 +00:00
Merge pull request #6232 from vector-im/maximee/6202_lls_improve_detection_pin_drop
[Location sharing] Improve detection of user panning on the map (PSF-1050)
This commit is contained in:
commit
cf556e2592
5 changed files with 33 additions and 16 deletions
|
@ -39,6 +39,7 @@ enum LocationSharingViewAction {
|
|||
case goToUserLocation
|
||||
case startLiveSharing
|
||||
case shareLiveLocation(timeout: LiveLocationSharingTimeout)
|
||||
case userDidPan
|
||||
}
|
||||
|
||||
enum LocationSharingViewModelResult {
|
||||
|
@ -70,9 +71,7 @@ struct LocationSharingViewState: BindableState {
|
|||
var highlightedAnnotation: LocationAnnotation?
|
||||
|
||||
/// Indicates whether the user has moved around the map to drop a pin somewhere other than their current location
|
||||
var isPinDropSharing: Bool {
|
||||
return bindings.pinLocation != nil
|
||||
}
|
||||
var isPinDropSharing: Bool = false
|
||||
|
||||
var showLoadingIndicator: Bool = false
|
||||
|
||||
|
|
|
@ -78,12 +78,16 @@ class LocationSharingViewModel: LocationSharingViewModelType, LocationSharingVie
|
|||
|
||||
completion?(.share(latitude: pinLocation.latitude, longitude: pinLocation.longitude, coordinateType: .pin))
|
||||
case .goToUserLocation:
|
||||
state.bindings.pinLocation = nil
|
||||
state.showsUserLocation = true
|
||||
state.isPinDropSharing = false
|
||||
case .startLiveSharing:
|
||||
self.startLiveLocationSharing()
|
||||
case .shareLiveLocation(let timeout):
|
||||
state.bindings.showingTimerSelector = false
|
||||
completion?(.shareLiveLocation(timeout: timeout.rawValue))
|
||||
case .userDidPan:
|
||||
state.showsUserLocation = false
|
||||
state.isPinDropSharing = true
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,9 @@ struct LocationSharingMapView: UIViewRepresentable {
|
|||
|
||||
/// Publish view errors if any
|
||||
let errorSubject: PassthroughSubject<LocationSharingViewError, Never>
|
||||
|
||||
/// Called when the user pan on the map
|
||||
var userDidPan: (() -> Void)?
|
||||
|
||||
// MARK: - UIViewRepresentable
|
||||
|
||||
|
@ -65,6 +68,9 @@ struct LocationSharingMapView: UIViewRepresentable {
|
|||
|
||||
let mapView = self.makeMapView()
|
||||
mapView.delegate = context.coordinator
|
||||
let panGesture = UIPanGestureRecognizer(target: context.coordinator, action: #selector(context.coordinator.didPan))
|
||||
panGesture.delegate = context.coordinator
|
||||
mapView.addGestureRecognizer(panGesture)
|
||||
return mapView
|
||||
}
|
||||
|
||||
|
@ -77,7 +83,7 @@ struct LocationSharingMapView: UIViewRepresentable {
|
|||
mapView.setCenter(highlightedAnnotation.coordinate, zoomLevel: Constants.mapZoomLevel, animated: false)
|
||||
}
|
||||
|
||||
if self.showsUserLocation && mapCenterCoordinate == nil {
|
||||
if self.showsUserLocation {
|
||||
mapView.showsUserLocation = true
|
||||
mapView.userTrackingMode = .follow
|
||||
} else {
|
||||
|
@ -106,7 +112,7 @@ struct LocationSharingMapView: UIViewRepresentable {
|
|||
@available(iOS 14, *)
|
||||
extension LocationSharingMapView {
|
||||
|
||||
class Coordinator: NSObject, MGLMapViewDelegate {
|
||||
class Coordinator: NSObject, MGLMapViewDelegate, UIGestureRecognizerDelegate {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
|
@ -126,7 +132,7 @@ extension LocationSharingMapView {
|
|||
return LocationAnnotationView(userLocationAnnotation: userLocationAnnotation)
|
||||
} else if let pinLocationAnnotation = annotation as? PinLocationAnnotation {
|
||||
return LocationAnnotationView(pinLocationAnnotation: pinLocationAnnotation)
|
||||
} else if annotation is MGLUserLocation && locationSharingMapView.mapCenterCoordinate == nil, let currentUserAvatarData = locationSharingMapView.userAvatarData {
|
||||
} else if annotation is MGLUserLocation, let currentUserAvatarData = locationSharingMapView.userAvatarData {
|
||||
// Replace default current location annotation view with a UserLocationAnnotatonView when the map is center on user location
|
||||
return LocationAnnotationView(avatarData: currentUserAvatarData)
|
||||
}
|
||||
|
@ -158,13 +164,7 @@ extension LocationSharingMapView {
|
|||
}
|
||||
|
||||
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
|
||||
locationSharingMapView.mapCenterCoordinate = mapView.centerCoordinate
|
||||
}
|
||||
|
||||
// MARK: Callout
|
||||
|
@ -182,11 +182,21 @@ extension LocationSharingMapView {
|
|||
}
|
||||
|
||||
func mapView(_ mapView: MGLMapView, tapOnCalloutFor annotation: MGLAnnotation) {
|
||||
|
||||
locationSharingMapView.onCalloutTap?(annotation)
|
||||
// Hide the callout
|
||||
mapView.deselectAnnotation(annotation, animated: true)
|
||||
}
|
||||
|
||||
// MARK: UIGestureRecognizer
|
||||
|
||||
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
|
||||
return gestureRecognizer is UIPanGestureRecognizer
|
||||
}
|
||||
|
||||
@objc
|
||||
func didPan() {
|
||||
locationSharingMapView.userDidPan?()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,10 @@ struct LocationSharingView: View {
|
|||
showsUserLocation: context.viewState.showsUserLocation,
|
||||
userLocation: $context.userLocation,
|
||||
mapCenterCoordinate: $context.pinLocation,
|
||||
errorSubject: context.viewState.errorSubject)
|
||||
errorSubject: context.viewState.errorSubject,
|
||||
userDidPan: {
|
||||
context.send(viewAction: .userDidPan)
|
||||
})
|
||||
if context.viewState.isPinDropSharing {
|
||||
LocationSharingMarkerView(backgroundColor: theme.colors.accent) {
|
||||
Image(uiImage: Asset.Images.locationPinIcon.image)
|
||||
|
|
1
changelog.d/6202.bugfix
Normal file
1
changelog.d/6202.bugfix
Normal file
|
@ -0,0 +1 @@
|
|||
Location sharing: Improve automatic detection of pin drop state
|
Loading…
Reference in a new issue