Fix live location start from modal location display

This commit is contained in:
Ilya Laktyushin 2020-10-29 00:09:07 +04:00
parent 2f13d11224
commit 0e3b3429dc
3 changed files with 16 additions and 9 deletions

View File

@ -158,6 +158,8 @@ final class LocationMapNode: ASDisplayNode, MKMapViewDelegate {
private weak var userLocationAnnotationView: MKAnnotationView? private weak var userLocationAnnotationView: MKAnnotationView?
private var headingArrowView: UIImageView? private var headingArrowView: UIImageView?
private weak var defaultUserLocationAnnotation: MKAnnotation?
private let pinDisposable = MetaDisposable() private let pinDisposable = MetaDisposable()
private var mapView: LocationMapView? { private var mapView: LocationMapView? {
@ -390,6 +392,8 @@ final class LocationMapNode: ASDisplayNode, MKMapViewDelegate {
func mapView(_ mapView: MKMapView, didAdd views: [MKAnnotationView]) { func mapView(_ mapView: MKMapView, didAdd views: [MKAnnotationView]) {
for view in views { for view in views {
if view.annotation is MKUserLocation { if view.annotation is MKUserLocation {
self.defaultUserLocationAnnotation = view.annotation
self.userLocationAnnotationView = view self.userLocationAnnotationView = view
if let headingArrowView = self.headingArrowView { if let headingArrowView = self.headingArrowView {
view.addSubview(headingArrowView) view.addSubview(headingArrowView)
@ -694,15 +698,15 @@ final class LocationMapNode: ASDisplayNode, MKMapViewDelegate {
guard let mapView = self.mapView else { guard let mapView = self.mapView else {
return return
} }
var annotations: [MKAnnotation] = [] var coordinates: [CLLocationCoordinate2D] = []
if let userAnnotation = self.userLocationAnnotation { if let location = self.currentUserLocation {
annotations.append(userAnnotation) coordinates.append(location.coordinate)
} }
annotations.append(contentsOf: self.annotations) coordinates.append(contentsOf: self.annotations.map { $0.coordinate })
var zoomRect: MKMapRect? var zoomRect: MKMapRect?
for annotation in annotations { for coordinate in coordinates {
let pointRegionRect = MKMapRect(region: MKCoordinateRegion(center: annotation.coordinate, latitudinalMeters: 100, longitudinalMeters: 100)) let pointRegionRect = MKMapRect(region: MKCoordinateRegion(center: coordinate, latitudinalMeters: 100, longitudinalMeters: 100))
if let currentZoomRect = zoomRect { if let currentZoomRect = zoomRect {
zoomRect = currentZoomRect.union(pointRegionRect) zoomRect = currentZoomRect.union(pointRegionRect)
} else { } else {

View File

@ -485,9 +485,11 @@ final class LocationViewControllerNode: ViewControllerTracingNode, CLLocationMan
if !strongSelf.reportedAnnotationsReady { if !strongSelf.reportedAnnotationsReady {
strongSelf.reportedAnnotationsReady = true strongSelf.reportedAnnotationsReady = true
if annotations.count > 0 {
strongSelf.onAnnotationsReady?() strongSelf.onAnnotationsReady?()
} }
} }
}
if let _ = proximityNotification { if let _ = proximityNotification {
strongSelf.headerNode.mapNode.activeProximityRadius = proximityNotificationRadius.flatMap { Double($0) } strongSelf.headerNode.mapNode.activeProximityRadius = proximityNotificationRadius.flatMap { Double($0) }
@ -496,7 +498,7 @@ final class LocationViewControllerNode: ViewControllerTracingNode, CLLocationMan
} }
let rightBarButtonAction: LocationViewRightBarButton let rightBarButtonAction: LocationViewRightBarButton
if location.liveBroadcastingTimeout != nil { if location.liveBroadcastingTimeout != nil {
if liveLocations.count > 1 { if annotations.count > 0 {
rightBarButtonAction = .showAll rightBarButtonAction = .showAll
} else { } else {
rightBarButtonAction = .none rightBarButtonAction = .none

View File

@ -38,7 +38,8 @@ private func presentLiveLocationController(context: AccountContext, peerId: Peer
}, openUrl: { _ in }, openUrl: { _ in
}, openPeer: { peer, navigation in }, openPeer: { peer, navigation in
}, callPeer: { _, _ in }, callPeer: { _, _ in
}, enqueueMessage: { _ in }, enqueueMessage: { message in
let _ = enqueueMessages(account: context.account, peerId: peerId, messages: [message]).start()
}, sendSticker: nil, }, sendSticker: nil,
setupTemporaryHiddenMedia: { _, _, _ in setupTemporaryHiddenMedia: { _, _, _ in
}, chatAvatarHiddenMedia: { _, _ in }, chatAvatarHiddenMedia: { _, _ in