Skip to content

Commit 2e07245

Browse files
97chosinteractord
authored andcommitted
feat: TabLinkNavigator - Added reloadLast method
1 parent af9c43d commit 2e07245

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

Examples/TabNavigator/02-TabInjectionParameter/TabInjectionParameter/Pages/Common/Step3/Step3Page.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct Step3Page: View {
1717
}
1818

1919
Button(action: {
20-
navigator.rootReloadLast(linkItem: .init(path: "step2", items: Step2InjectionData(message: "Replaced message!")), isAnimated: true) }) {
20+
navigator.reloadLast(linkItem: .init(path: "step2", items: Step2InjectionData(message: "Replaced message!")), isAnimated: true) }) {
2121
Text("Replaced 'Step3' message")
2222
}
2323

Sources/LinkNavigator/Core/Core/TabLinkNavigator/TabPartialNavigator.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,20 @@ extension TabPartialNavigator: TabLinkNavigatorProtocol {
227227
sheetOpen(item: linkItem, isAnimated: isAnimated, type: type)
228228
}
229229

230+
public func reloadLast(linkItem: LinkItem, isAnimated: Bool) {
231+
let viewControllers = navigationBuilder.build(item: linkItem)
232+
guard !viewControllers.isEmpty else { return }
233+
234+
let reloadedVC = viewControllers.reduce(currentController?.viewControllers ?? []) { current, next in
235+
guard let idx = current.firstIndex(where: { ($0 as? MatchPathUsable)?.matchPath == next.matchPath }) else { return current }
236+
var variableCurrentVC = current
237+
variableCurrentVC[idx] = next
238+
return variableCurrentVC
239+
}
240+
241+
currentController?.setViewControllers(reloadedVC, animated: isAnimated)
242+
}
243+
230244
public func rootReloadLast(linkItem: LinkItem, isAnimated: Bool) {
231245
let viewControllers = navigationBuilder.build(item: linkItem)
232246
guard !viewControllers.isEmpty else { return }

Sources/LinkNavigator/Core/Protocol/TabLinkNavigatorProtocol.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ public protocol TabLinkNavigatorProtocol {
112112
/// - Returns: An array of paths representing the range.
113113
func range(path: String) -> [String]
114114

115+
/// Reloads the last current item with the specified items.
116+
///
117+
/// - Parameters:
118+
/// - items: A string representing the raw QueryString for the items to reload.
119+
/// - isAnimated: A Boolean value indicating whether the reload should be animated.
120+
func reloadLast(linkItem: LinkItem, isAnimated: Bool)
121+
115122
/// Reloads the last root item with the specified items.
116123
///
117124
/// - Parameters:

0 commit comments

Comments
 (0)