As probably most of us I updated my iPhone to iOS 15. Sadly I have noticed that the dismissal of a view via the Binding of the NavigationLink is no longer working as it was on iOS 14. It works with the first link but not with the second or later.
iOS 14.5:
iOS 15.0:
I created a small project that recreates the issue:
import SwiftUI
struct ContentView: View {
enum NextView: Hashable {
case view1
}
@State private var nextView: NextView?
var body: some View {
NavigationView {
VStack {
Button("Next", action: { nextView = .view1 })
}
.background(Color.red)
.background(
NavigationLink(
tag: .view1,
selection: $nextView,
destination: {
View1 { dismissReason in
nextView = nil
}
},
label: EmptyView.init
)
)
}
}
}
struct View1: View {
enum NextView: Hashable {
case view2
}
enum DismissReason {
case back
}
let onDismiss: (DismissReason) -> Void
@State private var nextView: NextView?
var body: some View {
VStack {
Button("Back", action: { onDismiss(.back) })
Button("Next", action: { nextView = .view2 })
}
.background(Color.yellow)
.background(
NavigationLink(
tag: .view2,
selection: $nextView,
destination: {
View2 { dismissReason in
nextView = nil
}
},
label: EmptyView.init
)
)
}
}
struct View2: View {
enum NextView: Hashable {
case text
}
enum DismissReason {
case back
}
let onDismiss: (DismissReason) -> Void
@State private var nextView: NextView?
var body: some View {
VStack {
Button("Back", action: { onDismiss(.back) })
Button("Next", action: { nextView = .text })
}
.background(Color.green)
.background(
NavigationLink(
tag: .text,
selection: $nextView,
destination: { Text("Destination") },
label: EmptyView.init
)
)
}
}


