I'm trying to implement programatic nested navigation using NavigationStack and navigationDestination(isPresented:). But I can't figure out why I can't navigate back to A (button Go back to A is not working - nothing happens when I press it). Does anyone know what am I doing wrong?
struct Example: View {
@State var aPresented: Bool = false
@State var bPresented: Bool = false
var body: some View {
NavigationStack {
Button("Go to A") {
aPresented = true
}
.navigationDestination(isPresented: $aPresented, destination: { a })
}
}
var a: some View {
VStack {
Text("A")
Button("Go to B") {
bPresented = true
}
}
.navigationDestination(isPresented: $bPresented, destination: { b })
}
var b: some View {
VStack {
Text("B")
Button("Go back to A") {
bPresented = false
}
}
}
}