I am currently facing an issue in iOS 15 when dismissing a nested NavigationLink.
Here is a little code snippet:
struct ContentView: View {
var body: some View {
NavigationView {
NavigationLink {
View1()
} label: {
Text("Some link")
}
}
}
}
struct View1: View {
@State var isActive = false
var body: some View {
NavigationLink("View2", isActive: $isActive) {
View2(dismiss: $isActive)
}
}
}
struct View2: View {
@Environment(\.presentationMode) var presentationMode
@Binding var dismiss: Bool
var body: some View {
VStack {
Text("View2")
Button {
presentationMode.wrappedValue.dismiss() //this works
} label: {
Text("dismiss via presentationMode")
}
Button {
dismiss = false //this does not work
} label: {
Text("dismiss via binding")
}
}
}
}
As you can see, in View2 i have got two buttons which actually should both dismiss the NavigationLink.
However only the button "dismiss via presentationMode" will actually dismiss. When clicking on the second button "dismiss via binding", the value in View1 (isActive) is going to change, however the binding in the NavigationLink is not observing the change.
This code worked fine in iOS 14
Is this a known issue?