Skip to content

Commit 50414e7

Browse files
lks574interactord
authored andcommitted
fix: SingleNavigator - Modified 'backOrNext' Method
1 parent 129046e commit 50414e7

2 files changed

Lines changed: 15 additions & 18 deletions

File tree

Sources/LinkNavigator/Builder/SingleNavigationBuilder.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ extension SingleNavigationBuilder {
8282
/// - item: A `LinkItem` containing the paths and associated values.
8383
/// - Returns: A `RouteViewController` instance that matches the first path in the `LinkItem` or nil if no match is found.
8484
func lastPick(controller: UINavigationController?, item: LinkItem) -> RouteViewController? {
85-
guard let controller, let first = item.pathList.first else { return .none }
85+
guard let controller, let last = item.pathList.first else { return .none }
8686
return controller.viewControllers
8787
.compactMap { $0 as? RouteViewController }
88-
.last(where: { $0.matchPath == first })
88+
.last(where: { $0.matchPath == last })
8989
}
9090

9191
/// Filters out `RouteViewController` instances that match the paths in the `LinkItem` from the navigation stack.
@@ -99,4 +99,11 @@ extension SingleNavigationBuilder {
9999
.compactMap { $0 as? RouteViewController }
100100
.filter { !item.pathList.contains($0.matchPath) }
101101
}
102+
103+
public func isContainSequence(item: LinkItem) -> Bool {
104+
let currentPathJoin = routeBuilderList.map { $0.matchPath }.joined(separator: ",")
105+
let itemPathJoin = item.pathList.joined(separator: ",")
106+
107+
return currentPathJoin.contains(itemPathJoin)
108+
}
102109
}

Sources/LinkNavigator/Core/Core/SingleLinkNavigator.swift

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -216,16 +216,11 @@ extension SingleLinkNavigator {
216216
/// - linkItem: The link item containing the `ItemValue` to define the navigation endpoint.
217217
/// - isAnimated: A flag indicating whether the navigation should be animated.
218218
private func _backOrNext(linkItem: LinkItem, isAnimated: Bool) {
219-
guard let activeController else { return }
220-
221-
guard let pick = navigationBuilder.firstPick(controller: activeController, item: linkItem) else {
222-
activeController.push(
223-
viewController: navigationBuilder.pickBuild(item: linkItem),
224-
isAnimated: isAnimated)
219+
guard let pick = navigationBuilder.lastPick(controller: activeController, item: linkItem) else {
220+
activeController?.merge(new: navigationBuilder.build(item: linkItem), isAnimated: isAnimated)
225221
return
226222
}
227-
228-
activeController.popToViewController(pick, animated: isAnimated)
223+
activeController?.popToViewController(pick, animated: isAnimated)
229224
}
230225

231226
/// Navigates backwards or forwards from the root controller based on the first pick from the navigation builder.
@@ -234,16 +229,11 @@ extension SingleLinkNavigator {
234229
/// - linkItem: The link item containing the `ItemValue` to define the navigation endpoint.
235230
/// - isAnimated: A flag indicating whether the navigation should be animated.
236231
private func _rootBackOrNext(linkItem: LinkItem, isAnimated: Bool) {
237-
guard let rootController else { return }
238-
239-
guard let pick = navigationBuilder.firstPick(controller: rootController, item: linkItem) else {
240-
rootController.push(
241-
viewController: navigationBuilder.pickBuild(item: linkItem),
242-
isAnimated: isAnimated)
232+
guard let pick = navigationBuilder.lastPick(controller: rootController, item: linkItem) else {
233+
rootController?.merge(new: navigationBuilder.build(item: linkItem), isAnimated: isAnimated)
243234
return
244235
}
245-
246-
rootController.popToViewController(pick, animated: isAnimated)
236+
rootController?.popToViewController(pick, animated: isAnimated)
247237
}
248238

249239
// 다시

0 commit comments

Comments
 (0)