Add double tap top focus search bar for iPad

This commit is contained in:
Rizwan Mohamed Ibrahim 2023-11-21 11:51:51 +05:30
parent cfcf20d899
commit 450edb0574
No known key found for this signature in database
3 changed files with 27 additions and 18 deletions

View File

@ -12,6 +12,7 @@ import MastodonCore
protocol ContentSplitViewControllerDelegate: AnyObject {
func contentSplitViewController(_ contentSplitViewController: ContentSplitViewController, sidebarViewController: SidebarViewController, didSelectTab tab: MainTabBarController.Tab)
func contentSplitViewController(_ contentSplitViewController: ContentSplitViewController, sidebarViewController: SidebarViewController, didDoubleTapTab tab: MainTabBarController.Tab)
}
final class ContentSplitViewController: UIViewController, NeedsDependency {
@ -121,16 +122,7 @@ extension ContentSplitViewController: SidebarViewControllerDelegate {
}
func sidebarViewController(_ sidebarViewController: SidebarViewController, didDoubleTapItem item: SidebarViewModel.Item, sourceView: UIView) {
guard case let .tab(tab) = item, tab == .me else { return }
guard let authContext = authContext else { return }
assert(Thread.isMainThread)
guard let nextAccount = context.nextAccount(in: authContext) else { return }
Task { @MainActor in
let isActive = try await context.authenticationService.activeMastodonUser(domain: nextAccount.domain, userID: nextAccount.userID)
guard isActive else { return }
self.coordinator.setup()
}
guard case let .tab(tab) = item else { return }
delegate?.contentSplitViewController(self, sidebarViewController: sidebarViewController, didDoubleTapTab: tab)
}
}

View File

@ -157,6 +157,24 @@ extension RootSplitViewController: ContentSplitViewControllerDelegate {
}
}
func contentSplitViewController(_ contentSplitViewController: ContentSplitViewController, sidebarViewController: SidebarViewController, didDoubleTapTab tab: MainTabBarController.Tab) {
guard let _ = MainTabBarController.Tab.allCases.firstIndex(of: tab) else {
assertionFailure()
return
}
switch tab {
case .search:
// allow double tap to focus search bar only when is not primary display (iPad potrait)
guard !isPrimaryDisplay else {
return
}
contentSplitViewController.mainTabBarController.searchViewController?.searchBar.becomeFirstResponder()
default:
break
}
}
}
// MARK: - UISplitViewControllerDelegate

View File

@ -128,13 +128,12 @@ extension SidebarViewController {
sidebarLongPressGestureRecognizer.addTarget(self, action: #selector(SidebarViewController.sidebarLongPressGestureRecognizerHandler(_:)))
collectionView.addGestureRecognizer(sidebarLongPressGestureRecognizer)
// todo: reconsider the "double tap to change account" feature -> https://github.com/mastodon/mastodon-ios/issues/628
// let sidebarDoubleTapGestureRecognizer = UITapGestureRecognizer()
// sidebarDoubleTapGestureRecognizer.numberOfTapsRequired = 2
// sidebarDoubleTapGestureRecognizer.addTarget(self, action: #selector(SidebarViewController.sidebarDoubleTapGestureRecognizerHandler(_:)))
// sidebarDoubleTapGestureRecognizer.delaysTouchesEnded = false
// sidebarDoubleTapGestureRecognizer.cancelsTouchesInView = true
// collectionView.addGestureRecognizer(sidebarDoubleTapGestureRecognizer)
let sidebarDoubleTapGestureRecognizer = UITapGestureRecognizer()
sidebarDoubleTapGestureRecognizer.numberOfTapsRequired = 2
sidebarDoubleTapGestureRecognizer.addTarget(self, action: #selector(SidebarViewController.sidebarDoubleTapGestureRecognizerHandler(_:)))
sidebarDoubleTapGestureRecognizer.delaysTouchesEnded = false
sidebarDoubleTapGestureRecognizer.cancelsTouchesInView = true
collectionView.addGestureRecognizer(sidebarDoubleTapGestureRecognizer)
}