How to navigate from NavigationSplitView to new view opened full screen

59 views Asked by At

I want to ask for help with NavigationSplitView for iPad app. My idea is to have NavigationSplitView where I can display some filters/sections on the left side and list of objects on the right side (in the details section). But when user will tap on object, new view should appear with details. Problem is that NavigationSplitView gives me a navigation only in details section while I want to display view full screen. What I came up with is to have NavigationStack that has NavigationSplitView within it. But once item is tapped it will navigate inside NavigationSplitViews detail section. What will be proper approach for such problem? My current and very simple code for experiment with is:

struct ContentView: View {
    public var items: [DatabaseObject]?
    
    var body: some View {
        NavigationStack {
            NavigationSplitView {
                List {
                    Text("Filter 1")
                    Text("Filter 2")
                    Text("Filter 3")
                }
                .navigationTitle("Filters")
            } detail: {
                List {
                    if let items = items {
                        ForEach(items, id: \.id) { item in
                            NavigationLink {
                                Text("Hello. Details for person \(item.name)")
                            } label: {
                                Text(item.name)
                            }
                        }
                    }
                }
                .navigationTitle("Items")
                .toolbar(.hidden, for: .navigationBar)
            }
        }
    }
}
0

There are 0 answers