How to use NavigationLink inside SwiftUI sheet

656 Views Asked by At

I have 4 SwiftUI View:

  • The FirstView opens the SecondView using a sheet:

          .sheet(isPresented: $showSheet) {
              SecondView()
          }
    
  • The SecondView opens the ThirdView using a sheet too:

      .sheet(isPresented: $showSheet) {
              ThirdView()
      }
    

My expectations: I want ThirdView opens FourthView using NavigationLink (on full screen with Back button in the left corner):

            NavigationLink(destination: FourthView()) {
                Text("Open FourthView")
            }

but I'm having trouble with the view hierarchy. If I want to use NavigationLink, somewhere I have to define NavigationView. If I define NavigationView in the SecondView like this:

        .sheet(isPresented: $showSheet) {
            NavigationView {
                ThirdView()
            }
        }

, I have sheet view with Back button, but I want a full screen view with Back button.

Could you help me with this views hierarchy, where should I put NavigationView?

0

There are 0 best solutions below