Skip to content

Commit d2465f5

Browse files
committed
ViewStack is no longer an inner struct of the NavigationStack.
1 parent 14ab9fc commit d2465f5

File tree

1 file changed

+30
-32
lines changed

1 file changed

+30
-32
lines changed

Sources/NavigationStack/NavigationStack.swift

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -72,52 +72,50 @@ public class NavigationStack: ObservableObject {
7272
}
7373
}
7474
}
75+
}
7576

76-
//the actual stack
77-
private struct ViewStack {
78-
private var views = [ViewElement]()
77+
private struct ViewStack {
78+
private var views = [ViewElement]()
7979

80-
func peek() -> ViewElement? {
81-
views.last
82-
}
80+
func peek() -> ViewElement? {
81+
views.last
82+
}
8383

84-
var depth: Int {
85-
views.count
86-
}
84+
var depth: Int {
85+
views.count
86+
}
8787

88-
mutating func push(_ element: ViewElement) {
89-
guard indexForView(withId: element.id) == nil else {
90-
print("Duplicated view identifier: \"\(element.id)\". You are trying to push a view with an identifier that already exists on the navigation stack.")
91-
return
92-
}
93-
views.append(element)
88+
mutating func push(_ element: ViewElement) {
89+
guard indexForView(withId: element.id) == nil else {
90+
print("Duplicated view identifier: \"\(element.id)\". You are trying to push a view with an identifier that already exists on the navigation stack.")
91+
return
9492
}
93+
views.append(element)
94+
}
9595

96-
mutating func popToPrevious() {
97-
_ = views.popLast()
98-
}
96+
mutating func popToPrevious() {
97+
_ = views.popLast()
98+
}
9999

100-
mutating func popToView(withId identifier: String) {
101-
guard let viewIndex = indexForView(withId: identifier) else {
102-
print("Identifier \"\(identifier)\" not found. You are trying to pop to a view that doesn't exist.")
103-
return
104-
}
105-
views.removeLast(views.count - (viewIndex + 1))
100+
mutating func popToView(withId identifier: String) {
101+
guard let viewIndex = indexForView(withId: identifier) else {
102+
print("Identifier \"\(identifier)\" not found. You are trying to pop to a view that doesn't exist.")
103+
return
106104
}
105+
views.removeLast(views.count - (viewIndex + 1))
106+
}
107107

108-
mutating func popToRoot() {
109-
views.removeAll()
110-
}
108+
mutating func popToRoot() {
109+
views.removeAll()
110+
}
111111

112-
private func indexForView(withId identifier: String) -> Int? {
113-
views.firstIndex {
114-
$0.id == identifier
115-
}
112+
func indexForView(withId identifier: String) -> Int? {
113+
views.firstIndex {
114+
$0.id == identifier
116115
}
117116
}
118117
}
119118

120-
//the actual element in the stack
121119
struct ViewElement: Identifiable, Equatable {
122120
let id: String
123121
let wrappedElement: AnyView

0 commit comments

Comments
 (0)