diff --git a/LocationPicker/LocationPickerViewController.swift b/LocationPicker/LocationPickerViewController.swift index 6cbe07b..373c9aa 100644 --- a/LocationPicker/LocationPickerViewController.swift +++ b/LocationPicker/LocationPickerViewController.swift @@ -16,35 +16,35 @@ open class LocationPickerViewController: UIViewController { let action: (CLLocation) -> () } - public var completion: ((Location?) -> ())? + open var completion: ((Location?) -> ())? // region distance to be used for creation region when user selects place from search results - public var resultRegionDistance: CLLocationDistance = 600 + open var resultRegionDistance: CLLocationDistance = 600 /// default: true - public var showCurrentLocationButton = true + open var showCurrentLocationButton = true /// default: true - public var showCurrentLocationInitially = true + open var showCurrentLocationInitially = true /// default: false /// Select current location only if `location` property is nil. - public var selectCurrentLocationInitially = false + open var selectCurrentLocationInitially = false /// see `region` property of `MKLocalSearchRequest` /// default: false - public var useCurrentLocationAsHint = false + open var useCurrentLocationAsHint = false /// default: "Search or enter an address" - public var searchBarPlaceholder = "Search or enter an address" + open var searchBarPlaceholder = "Search or enter an address" /// default: "Search History" - public var searchHistoryLabel = "Search History" + open var searchHistoryLabel = "Search History" /// default: "Select" - public var selectButtonTitle = "Select" + open var selectButtonTitle = "Select" - public lazy var currentLocationButtonBackground: UIColor = { + open lazy var currentLocationButtonBackground: UIColor = { if let navigationBar = self.navigationController?.navigationBar, let barTintColor = navigationBar.barTintColor { return barTintColor @@ -52,15 +52,15 @@ open class LocationPickerViewController: UIViewController { }() /// default: .minimal - public var searchBarStyle: UISearchBar.Style = .minimal + open var searchBarStyle: UISearchBar.Style = .minimal /// default: .default - public var statusBarStyle: UIStatusBarStyle = .default + open var statusBarStyle: UIStatusBarStyle = .default @available(iOS 13.0, *) - public lazy var searchTextFieldColor: UIColor = .clear + open lazy var searchTextFieldColor: UIColor = .clear - public var mapType: MKMapType = .hybrid { + open var mapType: MKMapType = .hybrid { didSet { if isViewLoaded { mapView.mapType = mapType @@ -68,7 +68,7 @@ open class LocationPickerViewController: UIViewController { } } - public var location: Location? { + open var location: Location? { didSet { if isViewLoaded { searchBar.text = location.flatMap({ $0.title }) ?? "" @@ -90,21 +90,21 @@ open class LocationPickerViewController: UIViewController { var mapView: MKMapView! var locationButton: UIButton? - lazy var results: LocationSearchResultsViewController = { + lazy var results: LocationSearchResultsViewController = { let results = LocationSearchResultsViewController() results.onSelectLocation = { [weak self] in self?.selectedLocation($0) } results.searchHistoryLabel = self.searchHistoryLabel return results }() - lazy var searchController: UISearchController = { + open lazy var searchController: UISearchController = { let search = UISearchController(searchResultsController: self.results) search.searchResultsUpdater = self search.hidesNavigationBarDuringPresentation = false return search }() - lazy var searchBar: UISearchBar = { + open lazy var searchBar: UISearchBar = { let searchBar = self.searchController.searchBar searchBar.searchBarStyle = self.searchBarStyle searchBar.placeholder = self.searchBarPlaceholder @@ -276,7 +276,7 @@ open class LocationPickerViewController: UIViewController { } extension LocationPickerViewController: CLLocationManagerDelegate { - public func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { + open func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { guard let location = locations.first else { return } currentLocationListeners.forEach { $0.action(location) } currentLocationListeners = currentLocationListeners.filter { !$0.once } @@ -287,7 +287,7 @@ extension LocationPickerViewController: CLLocationManagerDelegate { // MARK: Searching extension LocationPickerViewController: UISearchResultsUpdating { - public func updateSearchResults(for searchController: UISearchController) { + open func updateSearchResults(for searchController: UISearchController) { guard let term = searchController.searchBar.text else { return } searchTimer?.invalidate() @@ -366,7 +366,7 @@ extension LocationPickerViewController { // MARK: MKMapViewDelegate extension LocationPickerViewController: MKMapViewDelegate { - public func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { + open func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { if annotation is MKUserLocation { return nil } let pin = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "annotation") @@ -390,7 +390,7 @@ extension LocationPickerViewController: MKMapViewDelegate { return button } - public func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) { + open func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) { completion?(location) if let navigation = navigationController, navigation.viewControllers.count > 1 { navigation.popViewController(animated: true) @@ -399,7 +399,7 @@ extension LocationPickerViewController: MKMapViewDelegate { } } - public func mapView(_ mapView: MKMapView, didAdd views: [MKAnnotationView]) { + open func mapView(_ mapView: MKMapView, didAdd views: [MKAnnotationView]) { let pins = mapView.annotations.filter { $0 is MKPinAnnotationView } assert(pins.count <= 1, "Only 1 pin annotation should be on map at a time") @@ -410,7 +410,7 @@ extension LocationPickerViewController: MKMapViewDelegate { } extension LocationPickerViewController: UIGestureRecognizerDelegate { - public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { + open func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { return true } } @@ -418,7 +418,7 @@ extension LocationPickerViewController: UIGestureRecognizerDelegate { // MARK: UISearchBarDelegate extension LocationPickerViewController: UISearchBarDelegate { - public func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) { + open func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) { // dirty hack to show history when there is no text in search bar // to be replaced later (hopefully) if let text = searchBar.text, text.isEmpty { @@ -426,7 +426,7 @@ extension LocationPickerViewController: UISearchBarDelegate { } } - public func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { + open func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { // remove location if user presses clear or removes text if searchText.isEmpty { location = nil