forked from zelo72/mastodon-ios
feat: add compact to regular split view controller expand restore logic
This commit is contained in:
parent
051f436abe
commit
ad0df8542e
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue