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

improve picker view searching experience #72

Open
wants to merge 2 commits into
base: new
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Source/Extensions/UIAlertController+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ extension UIAlertController {
/// - Parameters:
/// - vc: ViewController
/// - height: height of content viewController
func set(vc: UIViewController?, width: CGFloat? = nil, height: CGFloat? = nil) {
public func set(vc: UIViewController?, width: CGFloat? = nil, height: CGFloat? = nil) {
guard let vc = vc else { return }
setValue(vc, forKey: "contentViewController")
if let height = height {
Expand Down
13 changes: 11 additions & 2 deletions Source/Pickers/Locale/LocalePickerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,17 @@ extension LocalePickerViewController: UISearchResultsUpdating {
func updateSearchResults(for searchController: UISearchController) {
if let searchText = searchController.searchBar.text, searchController.isActive {
filteredInfo = []
if searchText.count > 0, let values = orderedInfo[String(searchText[searchText.startIndex])] {
filteredInfo.append(contentsOf: values.filter { $0.country.hasPrefix(searchText) })
if searchText.count > 0 {
filteredInfo = orderedInfo.values.reduce([], +).filter {
var propertis: [String?] = [$0.country]
if type == .phoneCode {
propertis.append($0.phoneCode)
} else if type == .currency {
propertis.append(contentsOf: [$0.currencyName, $0.currencyCode, $0.currencySymbol])
}
return propertis.compactMap { $0?.lowercased().contains(searchText.lowercased()) }
.reduce(false, { $0 || $1 })
}
} else {
orderedInfo.forEach { key, value in
filteredInfo += value
Expand Down