feat(UIKit): hide search view when annotation is selected
This commit is contained in:
@@ -15,11 +15,15 @@ class UIKitMapView: UIViewController, MKMapViewDelegate, CLLocationManagerDelega
|
|||||||
var viewModel: ViewModel
|
var viewModel: ViewModel
|
||||||
var oldDirections: [MKRoute] = []
|
var oldDirections: [MKRoute] = []
|
||||||
var oldDestination: MKMapItemAnnotation?
|
var oldDestination: MKMapItemAnnotation?
|
||||||
|
var detailsDisplayed = false
|
||||||
private var cancellables = Set<AnyCancellable>()
|
private var cancellables = Set<AnyCancellable>()
|
||||||
|
let searchViewConctroller: UIHostingController<SearchView>
|
||||||
let mapView : MKMapView = {
|
let mapView : MKMapView = {
|
||||||
let map = MKMapView()
|
let map = MKMapView()
|
||||||
map.showsUserTrackingButton = true
|
map.showsUserTrackingButton = true
|
||||||
map.showsUserLocation = true
|
map.showsUserLocation = true
|
||||||
|
map.selectableMapFeatures = .pointsOfInterest
|
||||||
|
map.pitchButtonVisibility = .adaptive
|
||||||
return map
|
return map
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -27,6 +31,7 @@ class UIKitMapView: UIViewController, MKMapViewDelegate, CLLocationManagerDelega
|
|||||||
init(locationManager: LocationManager, viewModel: ViewModel) {
|
init(locationManager: LocationManager, viewModel: ViewModel) {
|
||||||
self.locationManager = locationManager
|
self.locationManager = locationManager
|
||||||
self.viewModel = viewModel
|
self.viewModel = viewModel
|
||||||
|
self.searchViewConctroller = UIHostingController(rootView: SearchView(locationManager: locationManager, viewModel: viewModel))
|
||||||
super.init(nibName: nil, bundle: nil)
|
super.init(nibName: nil, bundle: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +49,7 @@ class UIKitMapView: UIViewController, MKMapViewDelegate, CLLocationManagerDelega
|
|||||||
}
|
}
|
||||||
|
|
||||||
override func viewDidAppear(_ animated: Bool) {
|
override func viewDidAppear(_ animated: Bool) {
|
||||||
setSearchView()
|
showSearchView()
|
||||||
}
|
}
|
||||||
|
|
||||||
private func setLocation() {
|
private func setLocation() {
|
||||||
@@ -66,8 +71,7 @@ class UIKitMapView: UIViewController, MKMapViewDelegate, CLLocationManagerDelega
|
|||||||
mapView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor).isActive = true
|
mapView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor).isActive = true
|
||||||
}
|
}
|
||||||
|
|
||||||
private func setSearchView() {
|
private func showSearchView() {
|
||||||
let searchViewConctroller = UIHostingController(rootView: SearchView(locationManager: locationManager, viewModel: viewModel))
|
|
||||||
searchViewConctroller.view.backgroundColor = .clear
|
searchViewConctroller.view.backgroundColor = .clear
|
||||||
searchViewConctroller.modalPresentationStyle = .pageSheet
|
searchViewConctroller.modalPresentationStyle = .pageSheet
|
||||||
searchViewConctroller.edgesForExtendedLayout = [.top, .bottom, .left, .right]
|
searchViewConctroller.edgesForExtendedLayout = [.top, .bottom, .left, .right]
|
||||||
@@ -114,6 +118,18 @@ class UIKitMapView: UIViewController, MKMapViewDelegate, CLLocationManagerDelega
|
|||||||
return renderer
|
return renderer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func mapView(_ mapView: MKMapView, didSelect annotation: any MKAnnotation) {
|
||||||
|
hideSearchView()
|
||||||
|
}
|
||||||
|
|
||||||
|
func mapView(_ mapView: MKMapView, didDeselect annotation: any MKAnnotation) {
|
||||||
|
showSearchView()
|
||||||
|
}
|
||||||
|
|
||||||
|
func hideSearchView() {
|
||||||
|
searchViewConctroller.dismiss(animated: true)
|
||||||
|
}
|
||||||
|
|
||||||
private func bindViewModel() {
|
private func bindViewModel() {
|
||||||
viewModel.$directions
|
viewModel.$directions
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
|
|||||||
Reference in New Issue
Block a user