Skip to content

Commit

Permalink
When replacing a root in a modal context, present a new modal flow
Browse files Browse the repository at this point in the history
  • Loading branch information
olivaresf committed Nov 20, 2023
1 parent 8ec5b89 commit 34812b1
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions Source/Turbo Navigator/TurboNavigationHierarchyController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class TurboNavigationHierarchyController {
case .clearAll:
clearAll()
case .replaceRoot:
replaceRoot(with: controller)
replaceRoot(with: controller, via: proposal)
case .none:
break // Do nothing.
}
Expand Down Expand Up @@ -189,12 +189,25 @@ class TurboNavigationHierarchyController {
delegate.refresh(navigationStack: .main)
}

private func replaceRoot(with controller: UIViewController) {
navigationController.dismiss(animated: true)
navigationController.setViewControllers([controller], animated: true)
private func replaceRoot(with controller: UIViewController, via proposal: VisitProposal) {

switch proposal.context {

case .default:
navigationController.dismiss(animated: true)
navigationController.setViewControllers([controller], animated: true)

if let visitable = controller as? Visitable {
delegate.visit(visitable, on: .main, with: .init(action: .replace))
if let visitable = controller as? Visitable {
delegate.visit(visitable, on: .main, with: .init(action: .replace))
}

case .modal:
navigationController.dismiss(animated: true) {
self.navigationController.present(controller, animated: true)
if let visitable = controller as? Visitable {
self.delegate.visit(visitable, on: .modal, with: proposal.options)
}
}
}
}
}

0 comments on commit 34812b1

Please sign in to comment.