diff --git a/Mastodon/Scene/Root/ContentSplitViewController.swift b/Mastodon/Scene/Root/ContentSplitViewController.swift index 877bd48d8..fdc5b5ba3 100644 --- a/Mastodon/Scene/Root/ContentSplitViewController.swift +++ b/Mastodon/Scene/Root/ContentSplitViewController.swift @@ -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) } } diff --git a/Mastodon/Scene/Root/MainTab/MainTabBarController.swift b/Mastodon/Scene/Root/MainTab/MainTabBarController.swift index cd0804b24..996d45a65 100644 --- a/Mastodon/Scene/Root/MainTab/MainTabBarController.swift +++ b/Mastodon/Scene/Root/MainTab/MainTabBarController.swift @@ -292,12 +292,11 @@ extension MainTabBarController { tabBarLongPressGestureRecognizer.delegate = self tabBar.addGestureRecognizer(tabBarLongPressGestureRecognizer) - // todo: reconsider the "double tap to change account" feature -> https://github.com/mastodon/mastodon-ios/issues/628 -// let tabBarDoubleTapGestureRecognizer = UITapGestureRecognizer() -// tabBarDoubleTapGestureRecognizer.numberOfTapsRequired = 2 -// tabBarDoubleTapGestureRecognizer.addTarget(self, action: #selector(MainTabBarController.tabBarDoubleTapGestureRecognizerHandler(_:))) -// tabBarDoubleTapGestureRecognizer.delaysTouchesEnded = false -// tabBar.addGestureRecognizer(tabBarDoubleTapGestureRecognizer) + let tabBarDoubleTapGestureRecognizer = UITapGestureRecognizer() + tabBarDoubleTapGestureRecognizer.numberOfTapsRequired = 2 + tabBarDoubleTapGestureRecognizer.addTarget(self, action: #selector(MainTabBarController.tabBarDoubleTapGestureRecognizerHandler(_:))) + tabBarDoubleTapGestureRecognizer.delaysTouchesEnded = false + tabBar.addGestureRecognizer(tabBarDoubleTapGestureRecognizer) self.isReadyForWizardAvatarButton = authContext != nil @@ -359,17 +358,10 @@ extension MainTabBarController { guard let tab = touchedTab(by: sender) else { return } switch tab { - case .me: - guard let authContext = authContext else { return } + case .search: 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() - } + // double tapping search tab opens the search bar without additional taps + searchViewController?.searchBar.becomeFirstResponder() default: break } diff --git a/Mastodon/Scene/Root/RootSplitViewController.swift b/Mastodon/Scene/Root/RootSplitViewController.swift index 10ed4c441..ea87f2500 100644 --- a/Mastodon/Scene/Root/RootSplitViewController.swift +++ b/Mastodon/Scene/Root/RootSplitViewController.swift @@ -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 diff --git a/Mastodon/Scene/Root/Sidebar/SidebarViewController.swift b/Mastodon/Scene/Root/Sidebar/SidebarViewController.swift index ac6342f83..b9a7d80f1 100644 --- a/Mastodon/Scene/Root/Sidebar/SidebarViewController.swift +++ b/Mastodon/Scene/Root/Sidebar/SidebarViewController.swift @@ -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) } diff --git a/Mastodon/Scene/Search/SearchDetail/SearchDetailViewController.swift b/Mastodon/Scene/Search/SearchDetail/SearchDetailViewController.swift index 9b1491ed7..d88c93b71 100644 --- a/Mastodon/Scene/Search/SearchDetail/SearchDetailViewController.swift +++ b/Mastodon/Scene/Search/SearchDetail/SearchDetailViewController.swift @@ -233,6 +233,7 @@ extension SearchDetailViewController { navigationItem.setHidesBackButton(true, animated: false) navigationItem.titleView = nil navigationItem.searchController = searchController + navigationItem.preferredSearchBarPlacement = .stacked searchController.searchBar.sizeToFit() }