Is it possible to drive NavigationSplitView navigation with a view in sidebar (left column) that is not a List
? All examples that I have seen from this year only contain List in sidebar.
I ask this because I would like to have a more complex layout in sidebar (or first view on iOS) that contains a mix of elements, some of them non-interactive and not targeting navigation. Here’s what I would like to do:
import SwiftUI
struct Thing: Identifiable, Hashable {
let id: UUID
let name: String
}
struct ContentView: View {
let things: [Thing]
@State private var selectedThingId: UUID?
var body: some View {
NavigationSplitView {
ScrollView(.vertical) {
VStack {
ForEach(things) { thing in
Button("Thing: \(thing.name) \( selectedThingId == thing.id ? "selected" : "" )") {
selectedThingId = thing.id
}
}
SomeOtherViewHere()
Button("Navigate to something else") { selectedThingId = someSpecificId }
}
}
} detail: {
// ZStack is workaround for known SDK bug
ZStack {
if let selectedThingId {
Text("There is a thing ID: \(selectedThingId)")
} else {
Text("There is no thing.")
}
}
}
}
}
This actually works as expected on iPadOS and macOS, but not iOS (iPhone). Tapping changes the selection as I see in the button label, but does not push anything to navigation stack, I remain stuck at home screen.
Also filed as FB10332749.