refactor: Minor code and UI improvements
This commit is contained in:
@@ -12,14 +12,22 @@ import MapKit
|
||||
|
||||
class EQNBaseMapViewController: EQNBaseViewController, MKMapViewDelegate {
|
||||
|
||||
/// Current filter
|
||||
var filter = EQNFiltroMappa.unGiorno {
|
||||
didSet {
|
||||
updateUI()
|
||||
}
|
||||
}
|
||||
/// Available filters
|
||||
var availableFilters: [EQNFiltroMappa] {
|
||||
[.unGiorno, .dodiciOre, .seiOre, .dueOre, .unOra, .dieciMinuti]
|
||||
}
|
||||
/// If `true`, the filter view is visible. Could be overridden by a subclass with a custom filter view
|
||||
var isFilterViewVisible: Bool {
|
||||
!availableFilters.isEmpty
|
||||
}
|
||||
|
||||
// MARK: - Internal
|
||||
|
||||
/// Annotations displayed on the map
|
||||
private var mapAnnotations = [MKAnnotation]()
|
||||
@@ -57,7 +65,7 @@ class EQNBaseMapViewController: EQNBaseViewController, MKMapViewDelegate {
|
||||
lazy var filtersView: UIView = {
|
||||
let view = UIView()
|
||||
view.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.backgroundColor = .lightGray
|
||||
view.backgroundColor = AppTheme.Colors.lightGray
|
||||
|
||||
// label with current selecte filter
|
||||
view.addSubview(filterLabel)
|
||||
@@ -106,13 +114,11 @@ class EQNBaseMapViewController: EQNBaseViewController, MKMapViewDelegate {
|
||||
// MARK: - Private
|
||||
|
||||
private func setupUI() {
|
||||
let isFilterVisible = !availableFilters.isEmpty
|
||||
|
||||
view.backgroundColor = .white
|
||||
view.addSubview(mapView)
|
||||
view.addSubview(closeButton)
|
||||
view.addSubview(containerView)
|
||||
if isFilterVisible {
|
||||
if isFilterViewVisible {
|
||||
view.addSubview(filtersView)
|
||||
}
|
||||
|
||||
@@ -124,18 +130,21 @@ class EQNBaseMapViewController: EQNBaseViewController, MKMapViewDelegate {
|
||||
bannerContainerHeightConstraint = containerView.heightAnchor.constraint(equalToConstant: 55.0)
|
||||
bannerContainerHeightConstraint?.isActive = true
|
||||
|
||||
if isFilterVisible {
|
||||
view.backgroundColor = filtersView.backgroundColor // trick to simulate a bigger filters view
|
||||
if isFilterViewVisible {
|
||||
filtersView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
|
||||
filtersView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
|
||||
filtersView.bottomAnchor.constraint(equalTo: containerView.topAnchor).isActive = true
|
||||
filtersView.heightAnchor.constraint(equalToConstant: 40.0).isActive = true
|
||||
}
|
||||
|
||||
if isFilterViewVisible && !isBannerVisible {
|
||||
view.backgroundColor = filtersView.backgroundColor // trick to simulate a bigger filters view
|
||||
}
|
||||
|
||||
mapView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
|
||||
mapView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
|
||||
mapView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
|
||||
mapView.bottomAnchor.constraint(equalTo: (isFilterVisible ? filtersView : containerView).topAnchor).isActive = true
|
||||
mapView.bottomAnchor.constraint(equalTo: (isFilterViewVisible ? filtersView : containerView).topAnchor).isActive = true
|
||||
}
|
||||
|
||||
// MARK: - View Lifecycle
|
||||
|
||||
Reference in New Issue
Block a user