feat: add compact to regular split view controller expand restore logic

This commit is contained in:
CMK 2021-09-29 17:37:32 +08:00
parent 051f436abe
commit ad0df8542e
2 changed files with 26 additions and 15 deletions

View File

@ -20,6 +20,8 @@ final public class SceneCoordinator {
weak var splitViewController: RootSplitViewController?
private(set) var secondaryStackHashValues = Set<Int>()
init(scene: UIScene, sceneDelegate: SceneDelegate, appContext: AppContext) {
self.scene = scene
self.sceneDelegate = sceneDelegate
@ -183,9 +185,13 @@ extension SceneCoordinator {
{
fallthrough
} else {
if secondaryStackHashValues.contains(presentingViewController.hashValue) {
secondaryStackHashValues.insert(viewController.hashValue)
}
presentingViewController.show(viewController, sender: sender)
}
case .showDetail:
secondaryStackHashValues.insert(viewController.hashValue)
let navigationController = AdaptiveStatusBarStyleNavigationController(rootViewController: viewController)
presentingViewController.showDetailViewController(navigationController, sender: sender)

View File

@ -200,21 +200,26 @@ extension RootSplitViewController: UISplitViewControllerDelegate {
_ svc: UISplitViewController,
displayModeForExpandingToProposedDisplayMode proposedDisplayMode: UISplitViewController.DisplayMode
) -> UISplitViewController.DisplayMode {
let compactNavigationController = mainTabBarController.selectedViewController as? UINavigationController
let viewControllers = compactNavigationController?.popToRootViewController(animated: true) ?? []
var supplementaryViewControllers: [UIViewController] = []
var secondaryViewControllers: [UIViewController] = []
for viewController in viewControllers {
if coordinator.secondaryStackHashValues.contains(viewController.hashValue) {
secondaryViewControllers.append(viewController)
} else {
supplementaryViewControllers.append(viewController)
}
}
if let supplementary = viewController(for: .supplementary) as? UINavigationController {
supplementary.setViewControllers(supplementary.viewControllers + supplementaryViewControllers, animated: false)
}
if let secondaryNavigationController = viewController(for: .secondary) as? UINavigationController {
secondaryNavigationController.setViewControllers(secondaryNavigationController.viewControllers + secondaryViewControllers, animated: false)
}
return proposedDisplayMode
}
func splitViewController(
_ splitViewController: UISplitViewController,
show vc: UIViewController,
sender: Any?
) -> Bool {
if !splitViewController.isCollapsed {
// display in .secondary when expand
splitViewController.showDetailViewController(vc, sender: sender)
return true
} else {
return false
}
}
}