fix: iPad layout update not take care of search tab selection logic issue

This commit is contained in:
CMK 2021-11-02 16:03:34 +08:00
parent 6d7de85f62
commit 07eab320f4
2 changed files with 38 additions and 16 deletions

View File

@ -351,6 +351,10 @@ extension MainTabBarController {
return viewController(of: NotificationViewController.self)
}
var searchViewController: SearchViewController? {
return viewController(of: SearchViewController.self)
}
}
// MARK: - UITabBarControllerDelegate

View File

@ -19,6 +19,8 @@ final class RootSplitViewController: UISplitViewController, NeedsDependency {
weak var context: AppContext! { willSet { precondition(!isViewLoaded) } }
weak var coordinator: SceneCoordinator! { willSet { precondition(!isViewLoaded) } }
private var isPrimaryDisplay = false
private(set) lazy var contentSplitViewController: ContentSplitViewController = {
let contentSplitViewController = ContentSplitViewController()
contentSplitViewController.context = context
@ -79,13 +81,6 @@ extension RootSplitViewController {
super.viewDidLoad()
updateBehavior(size: view.frame.size)
contentSplitViewController.$currentSupplementaryTab
.receive(on: DispatchQueue.main)
.sink { [weak self] _ in
guard let self = self else { return }
self.updateBehavior(size: self.view.frame.size)
}
.store(in: &disposeBag)
setupBackground(theme: ThemeService.shared.currentTheme.value)
ThemeService.shared.currentTheme
@ -97,6 +92,12 @@ extension RootSplitViewController {
.store(in: &disposeBag)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
updateBehavior(size: view.frame.size)
}
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
@ -109,15 +110,23 @@ extension RootSplitViewController {
}
private func updateBehavior(size: CGSize) {
switch contentSplitViewController.currentSupplementaryTab {
case .search:
hide(.primary)
default:
if size.width > 960 {
show(.primary)
isPrimaryDisplay = true
} else {
hide(.primary)
isPrimaryDisplay = false
}
switch (contentSplitViewController.currentSupplementaryTab, isPrimaryDisplay) {
case (.search, true):
// needs switch to other tab when primary display
// use FIFO queue save tab history
contentSplitViewController.currentSupplementaryTab = .home
default:
// do nothing
break
}
}
@ -141,6 +150,10 @@ extension RootSplitViewController: ContentSplitViewControllerDelegate {
}
switch tab {
case .search:
guard isPrimaryDisplay else {
// only control search tab behavior when primary display
fallthrough
}
guard let navigationController = searchViewController.navigationController else { return }
if navigationController.viewControllers.count == 1 {
searchViewController.searchBarTapPublisher.send()
@ -181,6 +194,11 @@ extension RootSplitViewController: UISplitViewControllerDelegate {
to.selectedIndex = from.selectedIndex
}
private static func transform(from: UINavigationController, to: UINavigationController) {
let viewControllers = from.popToRootViewController(animated: false) ?? []
to.viewControllers.append(contentsOf: viewControllers)
}
// .regular to .compact
func splitViewController(
_ svc: UISplitViewController,