Double tap tab bar to scroll to top

This commit is contained in:
Mingshen Sun 2021-01-17 22:27:50 -08:00
parent 8afc40a5a1
commit 9b2a047d38
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4

View file

@ -70,6 +70,7 @@ class PasswordNavigationViewController: UIViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
tabBarController?.delegate = self
configureNavigationItem()
configureTabBarItem()
configureNavigationBar()
@ -378,6 +379,21 @@ extension PasswordNavigationViewController: UISearchBarDelegate {
}
}
extension PasswordNavigationViewController: UITabBarControllerDelegate {
func tabBarController(_: UITabBarController, didSelect viewController: UIViewController) {
if viewController == navigationController {
let currentTime = Date().timeIntervalSince1970
let duration = currentTime - tapTabBarTime
tapTabBarTime = currentTime
if duration < 0.35, tableView.numberOfSections > 0 {
let topIndexPath = IndexPath(row: 0, section: 0)
tableView.scrollToRow(at: topIndexPath, at: .bottom, animated: true)
tapTabBarTime = 0
}
}
}
}
extension PasswordNavigationViewController: PasswordAlertPresenter {
private func syncPasswords() {
guard PasswordStore.shared.repositoryExists() else {