Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated access modifiers for easy sub-classing #65

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions LocationPicker/LocationPickerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,59 +16,59 @@ 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
} else { return .white }
}()

/// 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
}
}
}

public var location: Location? {
open var location: Location? {
didSet {
if isViewLoaded {
searchBar.text = location.flatMap({ $0.title }) ?? ""
Expand All @@ -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
Expand Down Expand Up @@ -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 }
Expand All @@ -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()
Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand All @@ -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")

Expand All @@ -410,23 +410,23 @@ 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
}
}

// 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 {
searchBar.text = " "
}
}

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
Expand Down