Recover search status back from the password detail

This commit is contained in:
Mingshen Sun 2023-03-10 22:01:18 -08:00
parent 5a91db4f76
commit 9ec7073e84

View file

@ -32,6 +32,7 @@ class PasswordNavigationViewController: UIViewController {
var viewingUnsyncedPasswords = false
var tapTabBarTime: TimeInterval = 0
var searchText: String?
lazy var passwordManager = PasswordManager(viewController: self)
@ -109,6 +110,16 @@ class PasswordNavigationViewController: UIViewController {
configureNavigationBar()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if searchText != nil {
DispatchQueue.main.async {
self.searchBar.text = self.searchText
self.searchController.isActive = true
}
}
}
private func configureSearchBar() {
if Defaults.isShowFolderOn {
searchBar.scopeButtonTitles = SearchBarScope.allCases.map(\.localizedName)
@ -388,6 +399,7 @@ extension PasswordNavigationViewController {
extension PasswordNavigationViewController: UISearchBarDelegate {
func search(matching text: String) {
searchText = text
dataSource?.showTableEntries(matching: text)
tableView.reloadData()
}
@ -414,6 +426,7 @@ extension PasswordNavigationViewController: UISearchBarDelegate {
searchBar.selectedScopeButtonIndex = SearchBarScope.current.rawValue
}
activateSearch(searchBar.selectedScopeButtonIndex)
search(matching: searchBar.text ?? "")
}
func searchBar(_: UISearchBar, textDidChange searchText: String) {
@ -431,6 +444,7 @@ extension PasswordNavigationViewController: UISearchBarDelegate {
func cancelSearch() {
configureTableView(in: parentPasswordEntity)
dataSource?.isSearchActive = false
searchText = nil
tableView.reloadData()
}
}