NavigationLink inside NavigationSplitView strange behaviours

I have a very simple NavigationSplitView setup. The first time you press the NavigationLink it pushes the next view, but then immediately dismisses it. Tap it again and it correctly pushes and stays on screen.

Then when tapping the second NavigationLink it pushes a view but just shows a yellow warning triangle and not the text.

Then when pressing the back button, it shows the initial view first, then the second view 🤷‍♂️

This is on iOS 16 beta 4.

Any idea what is going on here?

struct ContentView: View {

    @State var splitViewVisibility: NavigationSplitViewVisibility = .all

    var body: some View {
        NavigationSplitView(columnVisibility: $splitViewVisibility) {
            List {
                NavigationLink("First", destination: DetailView(string: "First"))
            }
        } detail: {
            Text("Select the first view from the list")
        }
        .navigationSplitViewStyle(.balanced)
    }
}



struct DetailView: View {

    var string: String

    var body: some View {
        NavigationStack() {
            List {
                NavigationLink("Second", value: "Second")
            }
            .navigationDestination(for: String.self, destination: { string in
                Text(string)
            })
        }
        .navigationTitle(string)
    }
}
Post not yet marked as solved Up vote post of dazboj Down vote post of dazboj
2.1k views

Replies

Defining the detail of the NavigationSplitView in the following manner works as expected (persisting the selection is needed for .compact class:

final class NavigationModel: ObservableObject {
    @Published var detailSelection: String?
}

@main
struct NavigationLink_711115App: App {
    @StateObject var navigationModel = NavigationModel()
    
    var body: some Scene {
        WindowGroup {
            ContentView()
                .environmentObject(navigationModel)
        }
    }
}

struct ContentView: View {
    @EnvironmentObject var navigationModel: NavigationModel
    @State var splitViewVisibility: NavigationSplitViewVisibility = .all

    var body: some View {
        NavigationSplitView(columnVisibility: $splitViewVisibility) {
            List(selection: $navigationModel.detailSelection) {
                NavigationLink("First", value: "First")
            }
        } detail: {
            if let detailSelection = navigationModel.detailSelection {
                DetailView(string: detailSelection)
            } else {
                Text("Select the first view from the list")
            }
        }
        .navigationSplitViewStyle(.balanced)
    }
}

struct DetailView: View {
    @EnvironmentObject var navigationModel: NavigationModel
    var string: String

    var body: some View {
        NavigationStack {
            List {
                NavigationLink("Second", value: "Second")
            }
            .navigationDestination(for: String.self, destination: { string in
                Text(string)
            })
        }
        .navigationTitle(string)
    }
}