From cca2a03b2fe1d84456e2e078f2c4d1be57dc97a3 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Fri, 20 Jan 2023 11:34:44 -0500 Subject: [PATCH] When routing the SplitNav responder chain through the root VC, go as deep into it as possible Makes keyboard shortcuts from, e.g., TimelineVC accessible when the root is TimelinesPageVC See #302 --- .../SegmentedPageViewController.swift | 6 ++++++ .../Utilities/SplitNavigationController.swift | 20 ++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Tusker/Screens/Utilities/SegmentedPageViewController.swift b/Tusker/Screens/Utilities/SegmentedPageViewController.swift index 7510eef4..6a618912 100644 --- a/Tusker/Screens/Utilities/SegmentedPageViewController.swift +++ b/Tusker/Screens/Utilities/SegmentedPageViewController.swift @@ -198,3 +198,9 @@ extension SegmentedPageViewController: StatusBarTappableViewController { return .continue } } + +extension SegmentedPageViewController: NestedResponderProvider { + var innerResponder: UIResponder? { + currentViewController + } +} diff --git a/Tusker/Screens/Utilities/SplitNavigationController.swift b/Tusker/Screens/Utilities/SplitNavigationController.swift index 77ee0db7..05f68922 100644 --- a/Tusker/Screens/Utilities/SplitNavigationController.swift +++ b/Tusker/Screens/Utilities/SplitNavigationController.swift @@ -283,7 +283,11 @@ private class SplitSecondaryNavigationController: EnhancedNavigationViewControll // ordinarily, the next responder in the chain would be the SplitNavigationController's view // but that would bypass the VC in the root nav, so we reroute the repsonder chain to include it // first seems to be nil when using the view debugger for some reason, so in that case, defer to super - owner.viewControllers.first?.view ?? super.next + if let root = owner.viewControllers.first { + return root.innermostResponder() ?? super.next + } else { + return super.next + } } private func configureSecondarySplitCloseButton(for viewController: UIViewController) { @@ -300,3 +304,17 @@ private class SplitSecondaryNavigationController: EnhancedNavigationViewControll } } + +protocol NestedResponderProvider { + var innerResponder: UIResponder? { get } +} + +extension UIResponder { + func innermostResponder() -> UIResponder? { + if let nestedProvider = self as? NestedResponderProvider { + return nestedProvider.innerResponder?.innermostResponder() ?? self + } else { + return self + } + } +}