I have 3 views - ContentView(), View1(), View2(). ContentView() being the main view is embedded in the NavigationView. It has a button that opens View1() MODALLY using .sheet(). View1 is also embedded in a new NavigationView and has a NavigationLink that navigates to View2().
The problem is I want to present View2() as a new stack but it is getting presented modally like View1().
Note: I had to embed View1() in a new NavigationView coz if I don't then NavigationLinks won't work on it.
import SwiftUI
struct ContentView: View {
@State private var isPresentingView1 = false
var body: some View {
NavigationView {
VStack {
Button("Open View1 Modally") {
isPresentingView1.toggle()
}
.sheet(isPresented: $isPresentingView1) {
View1()
}
}
}
}
}
struct View1: View {
var body: some View {
NavigationView{
NavigationLink("Open View2", destination: View2())
.navigationBarTitle("View 1")
}
}
}
struct View2: View {
var body: some View {
VStack {
Text("View 2 Content")
Spacer()
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}