feat: add split view layout update handler
This commit is contained in:
parent
c6fc5cc09d
commit
0ec20c6c88
|
@ -47,7 +47,7 @@ extension ContentSplitViewController {
|
||||||
navigationController?.setNavigationBarHidden(true, animated: false)
|
navigationController?.setNavigationBarHidden(true, animated: false)
|
||||||
|
|
||||||
addChild(sidebarViewController)
|
addChild(sidebarViewController)
|
||||||
sidebarViewController.view.translatesAutoresizingMaskIntoConstraints = false
|
sidebarViewController.view.translatesAutoresizingMaskIntoConstraints = false
|
||||||
view.addSubview(sidebarViewController.view)
|
view.addSubview(sidebarViewController.view)
|
||||||
sidebarViewController.didMove(toParent: self)
|
sidebarViewController.didMove(toParent: self)
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
|
|
|
@ -26,6 +26,8 @@ final class RootSplitViewController: UISplitViewController, NeedsDependency {
|
||||||
return contentSplitViewController
|
return contentSplitViewController
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
lazy var compactMainTabBarViewController = MainTabBarController(context: context, coordinator: coordinator)
|
||||||
|
|
||||||
init(context: AppContext, coordinator: SceneCoordinator) {
|
init(context: AppContext, coordinator: SceneCoordinator) {
|
||||||
self.context = context
|
self.context = context
|
||||||
self.coordinator = coordinator
|
self.coordinator = coordinator
|
||||||
|
@ -48,6 +50,7 @@ final class RootSplitViewController: UISplitViewController, NeedsDependency {
|
||||||
|
|
||||||
setViewController(UIViewController(), for: .primary)
|
setViewController(UIViewController(), for: .primary)
|
||||||
setViewController(contentSplitViewController, for: .secondary)
|
setViewController(contentSplitViewController, for: .secondary)
|
||||||
|
setViewController(compactMainTabBarViewController, for: .compact)
|
||||||
|
|
||||||
contentSplitViewController.sidebarViewController.view.layer.zPosition = 100
|
contentSplitViewController.sidebarViewController.view.layer.zPosition = 100
|
||||||
contentSplitViewController.mainTabBarController.view.layer.zPosition = 90
|
contentSplitViewController.mainTabBarController.view.layer.zPosition = 90
|
||||||
|
@ -108,85 +111,55 @@ extension RootSplitViewController {
|
||||||
// MARK: - UISplitViewControllerDelegate
|
// MARK: - UISplitViewControllerDelegate
|
||||||
extension RootSplitViewController: UISplitViewControllerDelegate {
|
extension RootSplitViewController: UISplitViewControllerDelegate {
|
||||||
|
|
||||||
// // .regular to .compact
|
private static func transform(from: UITabBarController, to: UITabBarController) {
|
||||||
// // move navigation stack from .supplementary & .secondary to .compact
|
let sourceNavigationControllers = from.viewControllers ?? []
|
||||||
// func splitViewController(
|
let targetNavigationControllers = to.viewControllers ?? []
|
||||||
// _ svc: UISplitViewController,
|
|
||||||
// topColumnForCollapsingToProposedTopColumn proposedTopColumn: UISplitViewController.Column
|
for (source, target) in zip(sourceNavigationControllers, targetNavigationControllers) {
|
||||||
// ) -> UISplitViewController.Column {
|
guard let source = source as? UINavigationController,
|
||||||
// switch proposedTopColumn {
|
let target = target as? UINavigationController
|
||||||
// case .compact:
|
else { continue }
|
||||||
// guard let index = MainTabBarController.Tab.allCases.firstIndex(of: currentSupplementaryTab) else {
|
let viewControllers = source.popToRootViewController(animated: false) ?? []
|
||||||
// assertionFailure()
|
_ = target.popToRootViewController(animated: false)
|
||||||
// break
|
target.viewControllers.append(contentsOf: viewControllers)
|
||||||
// }
|
}
|
||||||
// mainTabBarController.selectedIndex = index
|
|
||||||
// mainTabBarController.currentTab.value = currentSupplementaryTab
|
to.selectedIndex = from.selectedIndex
|
||||||
//
|
}
|
||||||
// guard let navigationController = mainTabBarController.selectedViewController as? UINavigationController else { break }
|
|
||||||
// navigationController.popToRootViewController(animated: false)
|
// .regular to .compact
|
||||||
// var viewControllers = navigationController.viewControllers // init navigation stack with topMost
|
func splitViewController(
|
||||||
//
|
_ svc: UISplitViewController,
|
||||||
// if let supplementaryNavigationController = viewController(for: .supplementary) as? UINavigationController {
|
topColumnForCollapsingToProposedTopColumn proposedTopColumn: UISplitViewController.Column
|
||||||
// // append supplementary
|
) -> UISplitViewController.Column {
|
||||||
// viewControllers.append(contentsOf: supplementaryNavigationController.popToRootViewController(animated: true) ?? [])
|
switch proposedTopColumn {
|
||||||
// }
|
case .compact:
|
||||||
// if let secondaryNavigationController = viewController(for: .secondary) as? UINavigationController {
|
RootSplitViewController.transform(from: contentSplitViewController.mainTabBarController, to: compactMainTabBarViewController)
|
||||||
// // append secondary
|
compactMainTabBarViewController.currentTab.value = contentSplitViewController.currentSupplementaryTab
|
||||||
// viewControllers.append(contentsOf: secondaryNavigationController.popToRootViewController(animated: true) ?? [])
|
|
||||||
// }
|
default:
|
||||||
// // set navigation stack
|
assertionFailure()
|
||||||
// navigationController.setViewControllers(viewControllers, animated: false)
|
}
|
||||||
//
|
|
||||||
// default:
|
return proposedTopColumn
|
||||||
// assertionFailure()
|
}
|
||||||
// }
|
|
||||||
//
|
// .compact to .regular
|
||||||
// return proposedTopColumn
|
func splitViewController(
|
||||||
// }
|
_ svc: UISplitViewController,
|
||||||
//
|
displayModeForExpandingToProposedDisplayMode proposedDisplayMode: UISplitViewController.DisplayMode
|
||||||
// // .compact to .regular
|
) -> UISplitViewController.DisplayMode {
|
||||||
// // restore navigation stack to .supplementary & .secondary
|
let compactNavigationController = compactMainTabBarViewController.selectedViewController as? UINavigationController
|
||||||
// func splitViewController(
|
|
||||||
// _ svc: UISplitViewController,
|
if let topMost = compactNavigationController?.topMost,
|
||||||
// displayModeForExpandingToProposedDisplayMode proposedDisplayMode: UISplitViewController.DisplayMode
|
topMost is AccountListViewController {
|
||||||
// ) -> UISplitViewController.DisplayMode {
|
topMost.dismiss(animated: false, completion: nil)
|
||||||
// let compactNavigationController = mainTabBarController.selectedViewController as? UINavigationController
|
}
|
||||||
//
|
|
||||||
// if let topMost = compactNavigationController?.topMost,
|
RootSplitViewController.transform(from: compactMainTabBarViewController, to: contentSplitViewController.mainTabBarController)
|
||||||
// topMost is AccountListViewController {
|
contentSplitViewController.currentSupplementaryTab = compactMainTabBarViewController.currentTab.value
|
||||||
// topMost.dismiss(animated: false, completion: nil)
|
|
||||||
// }
|
return proposedDisplayMode
|
||||||
//
|
}
|
||||||
// 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
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//extension UIView {
|
|
||||||
// func setNeedsLayoutForSubviews() {
|
|
||||||
// self.subviews.forEach({
|
|
||||||
// $0.setNeedsLayout()
|
|
||||||
// $0.setNeedsLayoutForSubviews()
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
Loading…
Reference in New Issue