Reputation: 31
I'd like to make a list in SwiftUI with collapsible/expandable sections (?), like in the home screen of Apple's Reminders app or in the Contacts or Mail app. There, the reminder lists are categorized by account (e.g. iCloud, Outlook, Gmail). The categories can be collapsed or expanded with the chevron button on the right.
Does anyone know how to make such a collapsible list?
I tried to divide the list into different sections and add the modifiers .listStyle(.sidebar)
and .listStyle(SidebarListStyle())
, but that didn't work.
I also tried to divide the list into sections and subsections (just a section
inside a section
) but that also didn't work.
Does anyone know how to make the lists/sections collapsible? Or can anyone maybe tell me why the .listStyle(.sidebar)
modifier didn't work?
I feel that it the layout from Apple should be easy to replicate because it's reused in so many of the Apps.
Thanks :)
EDIT: This is the code I'm using:
struct ContentView: View {
var body: some View {
List {
Section {
Text("Tasks")
Text("Tasks - school")
Text("Reminders")
} header: {
Text("iCloud")
.font(.title2)
.fontWeight(.heavy)
.foregroundStyle(.white)
.textCase(nil)
}
Section {
Text("School")
Text("Tasks")
} header: {
Text("Outlook")
.font(.title2)
.fontWeight(.heavy)
.foregroundStyle(.white)
.textCase(nil)
}
}
.listStyle(.sidebar)
}
}
This is the layout I get:
And this is the layout I want:
Upvotes: 0
Views: 878