Given is View1, View2 & View3.
I pushed View2 over View1.
Is there's a way to push View3 from View1 maintaining navigation stack?
struct ContentView: View {
@State var selection: String? = nil
var body: some View {
NavigationView {
VStack() {
NavigationLink(destination: Text("secand"), tag: "secand", selection: $selection) { }
NavigationLink(destination: Text("third"), tag: "third", selection: $selection) { }
Button("first") {
selection = "secand"
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
selection = "third"
}
}
}
}
}
}
What happens is that when the delay block executes View2 pops then View3 is pushed, I do not want View2 to be popped.
I want the stack to be View1 -> View2 -> View3
Is there's a way to make a view handle the navigation stack for a given flow without me putting NavigationLink
in every view in the flow.
A given scenario why would I want something like that is:
I have a ParentView which requests the user to chose from two different types of login, through Phone or through Email.
Both types will open an OTP verification view, I don't want to put the OTP view NavigationLink
's in both Email view & phone number view, I want to share it in ParentView only.