WWDC 2020で紹介された DisclosureGroup
を使えば、SwiftUI コンテンツのセクション(グループ)の表示・非表示が行えます。
struct ContentView: View {
@State var catMenuExpanded: Bool = false
@State var dogMenuExpanded: Bool = false
var body: some View {
DisclosureGroup("私の猫たち", isExpanded: $catMenuExpanded) {
Text("ネコノヒー")
Text("ムギ")
Text("レオ")
}.padding()
DisclosureGroup("私の犬たち", isExpanded: $dogMenuExpanded) {
Text("アズキ")
Text("マメ")
}.padding()
}
}