In a SwiftUI 2 navigation bar I have a list with multiple sections. All sections have a header, however I want the top section to never be closed and the elements will never be hidden. This is ask for only the first header and also want that the disclosure indicator / collapsing symbol to be gone or hidden.
Can this be done in SwiftUI 2? I want to have this to work in macOS and iPadOS.
@State var agendaViews: [String] = ["Agenda", "Client", "Next Client"]
@State var treatmentViews: [String] = ["Treatment", "Products", "Merchandising"]
@State var selectionAgenda: String?
var body: some View {
NavigationView {
VStack {
List(selection: $selectionAgenda) {
Section(header: ListHeader()) { // <<<<<<< For this section no Close Icon and No way to close this section.
ForEach(agendaViews, id: \.self) { string in
NavigationLink(destination: DetailsView(test: string)) {
Text(string)
}
}
}
Section(header: ListHeader2(), footer: ListFooter2()) {
ForEach(treatmentViews, id: \.self) { string in
NavigationLink(destination: DetailsView2(test: string)) {
Text(string)
}
}
}
}.listStyle(SidebarListStyle())
}
}
}
struct ListHeader1: View {
var body: some View {
HStack {
Image(systemName: "calendar")
Text("Agenda")
}
}
}
struct ListHeader2: View {
var body: some View {
HStack {
Image(systemName: "person.3")
Text("Clienten")
}
}
}
struct ListFooter3: View {
var body: some View {
Text("===")
}
}
I hope my question is clear. As always thank you very much.
Some image added to show that a section header has a close and open button.