NavigationLink in NavigationStack doesn't work on iOS 16.0 and iOS 16.1 beta

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)

  1. Pressing "SubView" button in RootView, it goes to SubView.
  2. Pressing "DetailView" button in SubView, it goes to DetailView.
  3. Pressing "Back" button, it goes to RootView. (Expect: it goes to SubView)

iOS 16.1 beta(20B5045d) / Xcode Version 14.1 beta 2 (14B5024i)

  1. Pressing "SubView" button in RootView, it goes to SubView.
  2. Pressing "DetailView" button in SubView, it goes to SubView.
  3. Pressing "DetailView" button in SubView, it goes to SubView. (Repeat) (Expect: it goes to DetailView)
  4. Pressing "Back" button in SubView, it goes to DetailView. (Expect: it goes to a previous view)

Still has this issue in Xcode Version 14.1 beta 3 (14B5033e), iOS 16.1 beta(20B5056e)

same here

I created a ViewModifier to work around this problem.

If you are not using NavigationPath, NavigationDestinationSelectedViewModifier may be available.

https://github.com/hmuronaka/NavigationDestinationSelectedViewModifier

Example


struct ContentView: View {
    var body: some View {
        NavigationLink("SubView") {
            SubView()
        }
    }
}

struct SubView: View {
    @State private var selection: Int?

    var body: some View {
        List(selection: $selection) {
            ForEach(0...10, id: \.self) { idx in
                NavigationLink(value: idx) {
                    Text("Detail \(idx)")
                }
            }
        }
        .navigationDestination(selected: $selection, destination: { value in
            DetailView(value: value)
        })
    }
}

struct DetailView: View {
    let value: Int
    var body: some View {
        Text("\(value)")
            .navigationTitle("Detail")
    }
}
NavigationLink in NavigationStack doesn't work on iOS 16.0 and iOS 16.1 beta
 
 
Q