0

Let's say my application has two pages; Login Page and Main Page. I created these two with SwiftUI View separately. How will I make the transition between them. I tried NavigationView but the second page opens with a NavigationBar (with the First Page named arrow). In summary, how can I switch between two views cleanly?

1 Answers1

1

you can do this simply with switch or if/else :)

class Wnd : View {
    @State var firstShown: Bool

    var body: some View {
        if firstShown {
             FirstView(firstShown: $firstShown)
        }
        else
        {
             SecondView(firstShown: $firstShown)
        }
    }
}

firstView and secondView have Binding to firstShown var


Another one solution is to use handlesExternalEvents for switching views.

sample of usage: https://stackoverflow.com/a/65415593/4423545


Another solution is to hide NavigationBar:

.navigationBarHidden(true)
Andrew_STOP_RU_WAR_IN_UA
  • 9,318
  • 5
  • 65
  • 101