2

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.

Ayman Ibrahim
  • 1,359
  • 15
  • 24
  • That will give bad user experience... you'd better proceed with custom transitions. – Asperi Jan 06 '21 at 20:06
  • You can push vc3 from vc1. If you push on your stack you will have vc1 -> vc2-> vc3, you could use a delegation mechanism to do that. What should be the final result once pushed? I suppose you would like to remove second view controller as you push controller 3? – Swift Rabbit Jan 06 '21 at 20:23

0 Answers0