Problem
I recently discovered SwiftUI's OutlineGroup in iOS 14 (I am using Xcode 12 beta 6 ). This works really well, either on its own or when using List, to compute "views and disclosure groups on demand from an underlying collection of tree-structured, identified data."
I.e. if you have a struct defined recursively, this works really well to build DisclosureGroup elements. However I am looking for something a little different that would allow me to build a "pull-down" (or hamburger) menu.
There's another control called Menu, in iOS 14, which renders a "pull-down" (or hamburger) menu exactly as I would like :
However I can't seem to use the 2 together to build a dynamic Menu based on data represented recursively, for example :
struct Tree<Value: Hashable>: Hashable {
let value: Value
var children: [Tree]? = nil
}
And menus built in the following manner :
struct SideMenu: View {
var body: some View {
Menu {
Button(action: {}) {
Image(systemName: "person")
.foregroundColor(.gray)
.imageScale(.large)
Text("Profile")
.foregroundColor(.gray)
.font(.headline)
}
Button(action: {}) {
Image(systemName: "person.3")
.foregroundColor(.gray)
.imageScale(.large)
Text("Family Members")
.foregroundColor(.gray)
.font(.headline)
}
Button(action: {}) {
Image(systemName: "calendar")
.foregroundColor(.gray)
.imageScale(.large)
Text("Events")
.foregroundColor(.gray)
.font(.headline)
}
} label: {
Image(systemName: "line.horizontal.3")
}
}
}
Question
Is there a way to build Menu from recursive data, similar to what is done with OutlineGroup ?
