Skip to content

Commit

Permalink
Simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando Olivares committed Jul 4, 2024
1 parent 0125f79 commit 160140c
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions Source/Turbo Navigator/TurboNavigationHierarchyController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,31 +165,24 @@ 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)
refreshIfTopViewControllerIsVisitable(from: .main, animated: proposal.animated)
stackToRefresh = .main
} else {
modalNavigationController.popViewController(animated: proposal.animated)
refreshIfTopViewControllerIsVisitable(from: .modal, animated: proposal.animated)
stackToRefresh = .modal
}
} else {
navigationController.popViewController(animated: proposal.animated)
refreshIfTopViewControllerIsVisitable(from: .main, animated: proposal.animated)
stackToRefresh = .main
}
}

private func refreshIfTopViewControllerIsVisitable(from stack: NavigationStackType, animated: Bool) {
if let navControllerTopmostVisitable = navController(for: stack).topViewController as? Visitable {
if animated {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.333) {
self.delegate.refreshVisitable(navigationStack: stack,
newTopmostVisitable: navControllerTopmostVisitable)
}
} else {
delegate.refreshVisitable(navigationStack: stack,
newTopmostVisitable: navControllerTopmostVisitable)
}

/// 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,
newTopmostVisitable: navControllerTopmostVisitable)
}
}

Expand Down

0 comments on commit 160140c

Please sign in to comment.