From 9b2a047d38aaf9fd0851a84c334a110a5e0de857 Mon Sep 17 00:00:00 2001 From: Mingshen Sun Date: Sun, 17 Jan 2021 22:27:50 -0800 Subject: [PATCH] Double tap tab bar to scroll to top --- .../PasswordNavigationViewController.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pass/Controllers/PasswordNavigationViewController.swift b/pass/Controllers/PasswordNavigationViewController.swift index e7353a6..75a08ad 100644 --- a/pass/Controllers/PasswordNavigationViewController.swift +++ b/pass/Controllers/PasswordNavigationViewController.swift @@ -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 {