in a book club app I’m trying to write, I have a NavigationSplitView
which displays a list of readers in a selectable List
that gives the user access to each reader’s comments on a given book. Above the list of readers is a home button “Book” that takes the user back to the book’s main page:
struct ProjectView: View
{
@State private var readers: [Reader]
init(readers: [Reader])
{
self.readers = readers
}
var body: some View
{
NavigationSplitView
{
List(selection: self.$selectedReader)
{
Button("Book")
{
self.selectedReader = nil
}
Divider()
ForEach (self.readers, id: .self)
{
reader in Text(reader.name)
}
}
}
detail:
{
if let selectedReader = self.selectedReader
{
ReaderView(reader: selectedReader)
}
else
{
BookView()
}
}
#if os(macOS)
.navigationSplitViewColumnWidth(min: 180, ideal: 200)
#endif
.navigationTitle(self.project.name)
}
}
I’m trying to make it so that “Book” will select just as the reader names in the reader list do, you can see what I mean in this video:
Does anyone know how to accomplish this? Or is it even possible?