Skip to content

Commit

Permalink
Clear snapshot cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando Olivares committed Jul 4, 2024
1 parent 2bf3eb0 commit 055beed
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 22 deletions.
22 changes: 7 additions & 15 deletions Source/Turbo Navigator/TurboNavigationHierarchyController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,21 @@ class TurboNavigationHierarchyController {
private func pop(via proposal: VisitProposal, refresh: Bool = false) {
if navigationController.presentedViewController != nil {
if modalNavigationController.viewControllers.count == 1 {
navigationController.dismiss(animated: proposal.animated)

if refresh {
refreshIfTopViewControllerIsVisitable(from: .main)
delegate.refresh(navigationStack: .main)
}
navigationController.dismiss(animated: proposal.animated)
} else {
modalNavigationController.popViewController(animated: proposal.animated)
if refresh {
refreshIfTopViewControllerIsVisitable(from: .modal)
delegate.refresh(navigationStack: .modal)
}
modalNavigationController.popViewController(animated: proposal.animated)
}
} else {
navigationController.popViewController(animated: proposal.animated)
if refresh {
refreshIfTopViewControllerIsVisitable(from: .main)
delegate.refresh(navigationStack: .main)
}
navigationController.popViewController(animated: proposal.animated)
}
}

Expand All @@ -173,18 +172,11 @@ class TurboNavigationHierarchyController {
}
}
}

private func refreshIfTopViewControllerIsVisitable(from stack: NavigationStackType) {
if let navControllerTopmostVisitable = navController(for: stack).topViewController as? Visitable {
self.delegate.refreshVisitable(navigationStack: stack,
newTopmostVisitable: navControllerTopmostVisitable)
}
}

private func clearAll(via proposal: VisitProposal) {
delegate.refresh(navigationStack: .main)
navigationController.dismiss(animated: proposal.animated)
navigationController.popToRootViewController(animated: proposal.animated)
refreshIfTopViewControllerIsVisitable(from: .main)
}

private func replaceRoot(with controller: UIViewController, via proposal: VisitProposal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,5 @@ protocol TurboNavigationHierarchyControllerDelegate: AnyObject {
///
/// - Parameters:
/// - navigationStack: the stack where the refresh is happening
/// - newTopmostVisitable: the visitable to be refreshed
func refreshVisitable(navigationStack: TurboNavigationHierarchyController.NavigationStackType,
newTopmostVisitable: Visitable)
func refresh(navigationStack: TurboNavigationHierarchyController.NavigationStackType)
}
7 changes: 3 additions & 4 deletions Source/Turbo Navigator/TurboNavigator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,12 @@ extension TurboNavigator: TurboNavigationHierarchyControllerDelegate {
}
}

func refreshVisitable(navigationStack: TurboNavigationHierarchyController.NavigationStackType,
newTopmostVisitable: any Visitable) {
func refresh(navigationStack: TurboNavigationHierarchyController.NavigationStackType) {
switch navigationStack {
case .main:
session.visit(newTopmostVisitable, reload: true)
session.markSnapshotCacheAsStale()
case .modal:
modalSession.visit(newTopmostVisitable, reload: true)
modalSession.markSnapshotCacheAsStale()
}
}
}
Expand Down

0 comments on commit 055beed

Please sign in to comment.