Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 14 additions & 22 deletions Mastodon/Scene/Root/MainTab/MainTabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,6 @@ extension MainTabBarController {
tabBarLongPressGestureRecognizer.delegate = self
tabBar.addGestureRecognizer(tabBarLongPressGestureRecognizer)

let tabBarDoubleTapGestureRecognizer = UITapGestureRecognizer()
tabBarDoubleTapGestureRecognizer.numberOfTapsRequired = 2
tabBarDoubleTapGestureRecognizer.addTarget(self, action: #selector(MainTabBarController.tabBarDoubleTapGestureRecognizerHandler(_:)))
tabBarDoubleTapGestureRecognizer.delaysTouchesEnded = false
tabBar.addGestureRecognizer(tabBarDoubleTapGestureRecognizer)

self.isReadyForWizardAvatarButton = authenticationBox != nil

$currentTab
Expand Down Expand Up @@ -337,22 +331,6 @@ extension MainTabBarController {
return _tab
}

@objc private func tabBarDoubleTapGestureRecognizerHandler(_ sender: UITapGestureRecognizer) {
guard sender.state == .ended else { return }
guard let tab = touchedTab(by: sender) else { return }

switch tab {
case .search:
assert(Thread.isMainThread)
// double tapping search tab opens the search bar without additional taps
searchViewController.searchBar.becomeFirstResponder()
case .home:
(homeTimelineViewController as? TimelineListViewController)?.scrollToTop()
default:
break
}
}

@objc private func tabBarLongPressGestureRecognizerHandler(_ sender: UILongPressGestureRecognizer) {
guard sender.state == .began else { return }
guard let tab = touchedTab(by: sender) else { return }
Expand Down Expand Up @@ -485,8 +463,22 @@ extension MainTabBarController: UITabBarControllerDelegate {
}

func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
let previousTab = currentTab
if let tab = Tab(rawValue: viewController.tabBarItem.tag), tab != .compose {
currentTab = tab

switch (currentTab, previousTab) {
case (.home, .home):
// When home is tapped again, scroll to top
(homeTimelineViewController as? TimelineListViewController)?.scrollToTop()
break
case (.search, .search):
// When search is tapped again, expand and focus the search bar
searchViewController.searchBar.becomeFirstResponder()
break
default:
break
}
}
}
}
Expand Down