The following sample code doesn't work as expected. In addition, the behavior differs between iOS 16.0 and iOS 16.1 beta.
If there is a workaround, please let me know. (I know that navigationDestination(isPresent:destination:) can be substituted in iOS 16.0, but it doesn't work in iOS 16.1 beta)
I reported this issue (FB11599516).
@main
struct StackViewSampleApp: App {
var body: some Scene {
WindowGroup {
NavigationStack {
ContentView()
}
}
}
}
struct ContentView: View {
var body: some View {
VStack {
NavigationLink("SubView") {
SubView()
}
}
.navigationDestination(for: Int.self) { v in
DetailView(value: v)
}
}
}
struct SubView: View {
var body: some View {
NavigationLink(value: 1) {
Text("DetailView")
}
.navigationTitle("SubView")
}
}
struct DetailView: View {
let value: Int
var body: some View {
Text("\(value)")
.navigationTitle("Detail")
}
}
Actual behavior
iOS 16.0 behavior / Xcode Version 14.0 (14A309)
- Pressing "SubView" button in RootView, it goes to SubView.
- Pressing "DetailView" button in SubView, it goes to DetailView.
- Pressing "Back" button, it goes to RootView. (Expect: it goes to SubView)
iOS 16.1 beta(20B5045d) / Xcode Version 14.1 beta 2 (14B5024i)
- Pressing "SubView" button in RootView, it goes to SubView.
- Pressing "DetailView" button in SubView, it goes to SubView.
- Pressing "DetailView" button in SubView, it goes to SubView. (Repeat) (Expect: it goes to DetailView)
- Pressing "Back" button in SubView, it goes to DetailView. (Expect: it goes to a previous view)