From d1588dda988c01564c6a5d9214db4aed67178cdc Mon Sep 17 00:00:00 2001 From: Rizwan Mohamed Ibrahim Date: Fri, 17 Nov 2023 14:46:00 +0530 Subject: [PATCH 1/4] Add option to focus the search bar when double tapping the search tab bar - Enables double tap for tab bar(s) - Hides double tap for me tab (as per previous comment) - Adds search tab double tab option to focus the search bar --- .../Root/MainTab/MainTabBarController.swift | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/Mastodon/Scene/Root/MainTab/MainTabBarController.swift b/Mastodon/Scene/Root/MainTab/MainTabBarController.swift index cd0804b24..bf14825a2 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,22 @@ extension MainTabBarController { guard let tab = touchedTab(by: sender) else { return } switch tab { - case .me: - guard let authContext = authContext else { return } + // todo: reconsider the "double tap to change account" feature -> https://github.com/mastodon/mastodon-ios/issues/628 +// case .me: +// 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() +// } + 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?.searchBarTapPublisher.send("") default: break } From cfcf20d899eae8e3e33305b243cfd4047cebde38 Mon Sep 17 00:00:00 2001 From: Rizwan Mohamed Ibrahim Date: Mon, 20 Nov 2023 20:54:08 +0530 Subject: [PATCH 2/4] Clean up commented out code related to me tab --- .../Scene/Root/MainTab/MainTabBarController.swift | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/Mastodon/Scene/Root/MainTab/MainTabBarController.swift b/Mastodon/Scene/Root/MainTab/MainTabBarController.swift index bf14825a2..996d45a65 100644 --- a/Mastodon/Scene/Root/MainTab/MainTabBarController.swift +++ b/Mastodon/Scene/Root/MainTab/MainTabBarController.swift @@ -358,22 +358,10 @@ extension MainTabBarController { guard let tab = touchedTab(by: sender) else { return } switch tab { - // todo: reconsider the "double tap to change account" feature -> https://github.com/mastodon/mastodon-ios/issues/628 -// case .me: -// 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() -// } case .search: assert(Thread.isMainThread) // double tapping search tab opens the search bar without additional taps - searchViewController?.searchBarTapPublisher.send("") + searchViewController?.searchBar.becomeFirstResponder() default: break } From 450edb05744f16cc2b803320107c6a0136fae2ad Mon Sep 17 00:00:00 2001 From: Rizwan Mohamed Ibrahim Date: Tue, 21 Nov 2023 11:51:51 +0530 Subject: [PATCH 3/4] Add double tap top focus search bar for iPad --- .../Root/ContentSplitViewController.swift | 14 +++----------- .../Scene/Root/RootSplitViewController.swift | 18 ++++++++++++++++++ .../Root/Sidebar/SidebarViewController.swift | 13 ++++++------- 3 files changed, 27 insertions(+), 18 deletions(-) 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/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) } From 5b55be092aa4a65d8527b9b4a8b5b8efa11eda76 Mon Sep 17 00:00:00 2001 From: Rizwan Mohamed Ibrahim Date: Tue, 21 Nov 2023 11:53:13 +0530 Subject: [PATCH 4/4] Fix crash on iPad non primary display focusing search bar Crash happens when we try to focus search bar when in iPad portrait because of custom hight search bar don't have correct intrinsic size --- .../Scene/Search/SearchDetail/SearchDetailViewController.swift | 1 + 1 file changed, 1 insertion(+) 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() }