I'm having trouble setting up a NavigationSplit view and passing details to NavigationTitle of the Detail view.
Here's my basic View setup
struct SplitView: View {
private let folder = xFolder.folderList
@State var selectedFolder: xFolder?
var body: some View {
NavigationSplitView{
List(folder,selection: $selectedFolder) {folder in
NavigationLink(destination: DetailView()) { sideBarEntry(folder.title, folder.icon, folder.count, folder.color).tag(folder) }
}
.listStyle(SidebarListStyle())
.tint(.gray.opacity(0.2))
.navigationTitle("App Name")
}
detail: {
DetailView()
.padding(.horizontal)
.navigationTitle(selectedFolder?.title ?? "Hello")
}
.navigationSplitViewStyle(.balanced)
}
}
struct DetailView: View {
@State var searchString:String = ""
var body: some View {
NavigationStack{
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundColor(.accentColor)
Text("Hello, world!")
}
.padding()
.searchable(
text: $searchString,
placement: .navigationBarDrawer(displayMode: .automatic),
prompt: "Search"
)
.toolbar(content: mainToolBarContent)
}
}
@ToolbarContentBuilder
func mainToolBarContent() -> some ToolbarContent {
ToolbarItem(id: "View", placement: .navigationBarTrailing) {
Button(action: {}
,label: {
Image(systemName: "star" )
.font(.body)
})
}
}
}
And here's the data structure
struct xFolder: Identifiable, Hashable {
let title: String
let icon: String
let count: Int //UnreadCount
let color: Color //tint Color
let id = UUID()
}
extension xFolder {
static var folderList: [xFolder] {
[.init(title: "Overdue", icon: "calendar.badge.exclamationmark", count:4, color: .pink),
.init(title: "Unsynced", icon: "exclamationmark.arrow.triangle.2.circlepath", count:2, color: .pink),
.init(title: "Completed", icon: "archivebox", count: 1442, color: .blue),
]
}
}
/// Sidebar List Style
extension View {
@ViewBuilder
func sideBarEntry(_ title: String, _ icon: String, _ count: Int, _ color: Color ) -> some View {
HStack {
Image(systemName: icon)
// .symbolRenderingMode(.palette)
// .foregroundStyle(Color("exoDynamic"), Color(.systemBackground))
.foregroundColor(color)
Text(title)
.foregroundColor(.primary)
}
.badge(Text("\(count)").foregroundColor(.secondary))
}
}
When I select a folder/entry on the NavigationSplitView I expect the NavigationTitle to be passed to the Detail view but I don't see that happening...