Workaround for tab bar content VC not being in responder chain almost ever

Closes #544, #179
This commit is contained in:
Shadowfacts 2024-12-15 13:18:47 -05:00
parent 20692b0630
commit 242c60d74d
6 changed files with 55 additions and 0 deletions

View File

@ -484,3 +484,11 @@ extension ConversationViewController: StatusBarTappableViewController {
}
}
}
extension ConversationViewController: RefreshableViewController {
func refresh() {
Task {
await refreshContext()
}
}
}

View File

@ -151,6 +151,22 @@ class BaseMainTabBarViewController: UITabBarController, FastAccountSwitcherViewC
return false
#endif // !os(visionOS)
}
// MARK: Keyboard shortcuts
override func target(forAction action: Selector, withSender sender: Any?) -> Any? {
// This is a silly workaround for when the sidebar is focused (and therefore first responder), which,
// unfortunately, is almost always. Because the content view controller then isn't in the responder chain,
// we manually delegate to the top view controller if possible.
if action == #selector(RefreshableViewController.refresh),
let selected = selectedViewController as? NavigationControllerProtocol,
let top = selected.topViewController as? RefreshableViewController {
return top
} else {
return super.target(forAction: action, withSender: sender)
}
}
}
extension BaseMainTabBarViewController: TuskerNavigationDelegate {

View File

@ -219,6 +219,19 @@ class MainSplitViewController: UISplitViewController {
@objc func handleComposeKeyCommand() {
compose(editing: nil)
}
override func target(forAction action: Selector, withSender sender: Any?) -> Any? {
// This is a silly workaround for when the sidebar is focused (and therefore first responder), which,
// unfortunately, is almost always. Because the content view controller then isn't in the responder chain,
// we manually delegate to the top view controller if possible.
if action == #selector(RefreshableViewController.refresh),
traitCollection.horizontalSizeClass == .regular,
let top = secondaryNavController.topViewController as? RefreshableViewController {
return top
} else {
return super.target(forAction: action, withSender: sender)
}
}
}

View File

@ -180,3 +180,9 @@ extension NotificationsPageViewController: StateRestorableViewController {
return currentPage.userActivity(accountID: mastodonController.accountInfo!.id)
}
}
extension NotificationsPageViewController: RefreshableViewController {
func refresh() {
(currentViewController as? RefreshableViewController)?.refresh()
}
}

View File

@ -393,3 +393,9 @@ extension ProfileViewController: StatusBarTappableViewController {
return currentViewController.handleStatusBarTapped(xPosition: xPosition)
}
}
extension ProfileViewController: RefreshableViewController {
func refresh() {
currentViewController.refresh()
}
}

View File

@ -212,3 +212,9 @@ extension TimelinesPageViewController: StateRestorableViewController {
return (currentViewController as? TimelineViewController)?.stateRestorationActivity()
}
}
extension TimelinesPageViewController: RefreshableViewController {
func refresh() {
(currentViewController as? RefreshableViewController)?.refresh()
}
}