I would like to create a master-detail view inside the Settings screen for my Mac app. I am trying to use a NavigationSplitView nested inside the top-level Settings TabView. (Reduced code below).
However, the sidebar of the NavigationSplitView interferes with the TabView - the TabView appears to be in the detail of the NavigationSplitView even though it is its parent. I have seen others having the reverse issues with TabViews in NavigationSplitViews. Is this a known bug please?
struct SettingsView: View {
var body: some View {
TabView {
GeneralSettingsView()
.tabItem {
Label("General", systemImage: "gear") }
.tag(SettingsSection.general)
TypesView()
.tabItem {
Label("Types", systemImage: "star") }
.tag(SettingsSection.types)
}
.frame(width: 375, height: 150)
}
}
struct TypesView: View {
@Environment(\.modelContext) private var modelContext
@Query private var types: [ItemType]
@State private var selectedType: ItemType?
var body: some View {
NavigationSplitView {
List {
ForEach(types) { type in
NavigationLink {
TypeView(type: type)
} label: {
Text(type.name)
}
}
}
} detail: {
Text("Select a Type")
}
}
}
@Gillies This isn't a bug, in this case the NavigationSplitView
is the content of Types Tab. I would suggest you look into the new TabView
API, you could specify a sidebarAdaptable tabViewStyle which shows a sidebar on macOS