Skip to content

Commit

Permalink
Add keyboard dismiss on scroll as per ship review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
amddg44 committed Mar 25, 2024
1 parent 1c53967 commit 72c653d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions DuckDuckGo/AutofillLoginListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ final class AutofillLoginListViewModel: ObservableObject {
}
}
var authenticationNotRequired = false
var isCancelingSearch = false

@Published private var accounts = [SecureVaultModels.WebsiteAccount]()
private var accountsToSuggest = [SecureVaultModels.WebsiteAccount]()
private var cancellables: Set<AnyCancellable> = []
Expand Down
27 changes: 24 additions & 3 deletions DuckDuckGo/AutofillLoginSettingsListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ final class AutofillLoginSettingsListViewController: UIViewController {
private lazy var searchController: UISearchController = {
let searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.searchBar.delegate = self
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.placeholder = UserText.autofillLoginListSearchPlaceholder
navigationItem.hidesSearchBarWhenScrolling = false
Expand Down Expand Up @@ -180,8 +181,8 @@ final class AutofillLoginSettingsListViewController: UIViewController {

}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
authenticate()
}

Expand Down Expand Up @@ -922,12 +923,32 @@ extension AutofillLoginSettingsListViewController: UISearchResultsUpdating {

func updateSearchResults(for searchController: UISearchController) {
viewModel.isSearching = searchController.isActive
if let query = searchController.searchBar.text {

if viewModel.isSearching {
viewModel.isCancelingSearch = false
}

if !viewModel.isCancelingSearch, let query = searchController.searchBar.text {
viewModel.filterData(with: query)
emptySearchView.query = query
tableView.reloadData()
}
}

func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
searchController.searchBar.resignFirstResponder()
}
}

extension AutofillLoginSettingsListViewController: UISearchBarDelegate {

func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
viewModel.isCancelingSearch = true
viewModel.isSearching = false

viewModel.filterData(with: "")
tableView.reloadData()
}
}

// MARK: Keyboard
Expand Down

0 comments on commit 72c653d

Please sign in to comment.