diff --git a/Source/Turbo Navigator/TurboNavigationHierarchyController.swift b/Source/Turbo Navigator/TurboNavigationHierarchyController.swift index b9868b1..742e38e 100644 --- a/Source/Turbo Navigator/TurboNavigationHierarchyController.swift +++ b/Source/Turbo Navigator/TurboNavigationHierarchyController.swift @@ -165,23 +165,23 @@ class TurboNavigationHierarchyController { } private func refresh(via proposal: VisitProposal) { - let stackToRefresh: NavigationStackType if navigationController.presentedViewController != nil { if modalNavigationController.viewControllers.count == 1 { navigationController.dismiss(animated: proposal.animated) - stackToRefresh = .main + refreshIfTopViewControllerIsVisitable(from: .main) } else { modalNavigationController.popViewController(animated: proposal.animated) - stackToRefresh = .modal + refreshIfTopViewControllerIsVisitable(from: .modal) } } else { navigationController.popViewController(animated: proposal.animated) - stackToRefresh = .main + refreshIfTopViewControllerIsVisitable(from: .main) } - - /// Once the navigation stack is updated, notify the session so it refreshes the topmost visitable. - if let navControllerTopmostVisitable = navController(for: stackToRefresh).topViewController as? Visitable { - self.delegate.refreshVisitable(navigationStack: stackToRefresh, + } + + private func refreshIfTopViewControllerIsVisitable(from stack: NavigationStackType) { + if let navControllerTopmostVisitable = navController(for: stack).topViewController as? Visitable { + self.delegate.refreshVisitable(navigationStack: stack, newTopmostVisitable: navControllerTopmostVisitable) } } @@ -189,7 +189,7 @@ class TurboNavigationHierarchyController { private func clearAll(via proposal: VisitProposal) { navigationController.dismiss(animated: proposal.animated) navigationController.popToRootViewController(animated: proposal.animated) - refreshIfTopViewControllerIsVisitable(from: .main, animated: proposal.animated) + refreshIfTopViewControllerIsVisitable(from: .main) } private func replaceRoot(with controller: UIViewController, via proposal: VisitProposal) {