Tap tab bar to go back previous folder, double tap will scroll to top

This commit is contained in:
Bob Sun 2017-03-02 22:55:41 +08:00
parent cbbd7e08b6
commit faf1ece5c3
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4

View file

@ -21,11 +21,13 @@ struct PasswordsTableEntry {
var passwordEntity: PasswordEntity?
}
class PasswordsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
class PasswordsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UITabBarControllerDelegate {
private var passwordsTableEntries: [PasswordsTableEntry] = []
private var filteredPasswordsTableEntries: [PasswordsTableEntry] = []
private var parentPasswordEntity: PasswordEntity? = nil
private var tapTabBarTime: TimeInterval = 0
var sections : [(index: Int, length :Int, title: String)] = Array()
var searchActive : Bool = false
lazy var searchController: UISearchController = {
@ -151,8 +153,8 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
setNavigationItemTitle()
initPasswordsTableEntries(parent: nil)
addNotificationObservers()
generateSections(item: passwordsTableEntries)
tabBarController!.delegate = self
tableView.delegate = self
tableView.dataSource = self
definesPresentationContext = true
@ -230,6 +232,7 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
}
func backAction(_ sender: Any?) {
guard Defaults[.isShowFolderOn] else { return }
initPasswordsTableEntries(parent: parentPasswordEntity?.parent)
reloadTableView(data: passwordsTableEntries)
}
@ -419,6 +422,21 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
syncPasswords()
refreshControl.endRefreshing()
}
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
if viewController == self.navigationController {
let currentTime = Date().timeIntervalSince1970
let duration = currentTime - self.tapTabBarTime
self.tapTabBarTime = currentTime
if duration < 0.35 {
let topIndexPath = IndexPath(row: 0, section: 0)
tableView.scrollToRow(at: topIndexPath, at: .bottom, animated: true)
self.tapTabBarTime = 0
return
}
backAction(self)
}
}
}
extension PasswordsViewController: UISearchResultsUpdating {