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
This commit is contained in:
Shadowfacts 2023-01-20 11:34:44 -05:00
parent 1a64bfcef8
commit cca2a03b2f
2 changed files with 25 additions and 1 deletions

View File

@ -198,3 +198,9 @@ extension SegmentedPageViewController: StatusBarTappableViewController {
return .continue
}
}
extension SegmentedPageViewController: NestedResponderProvider {
var innerResponder: UIResponder? {
currentViewController
}
}

View File

@ -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
}
}
}