Does embedding a Table inside a DisclosureGroup not work? If I uncomment the DisclosureGroup in the code below, the table doesn't display. Is there anything that I can do to make it work?
import SwiftUI
import PlaygroundSupport
class Foo: Identifiable {
let id: Int
let num: Double
init(id: Int, num: Double) {
self.id = id
self.num = num
}
}
typealias FooArray = [Foo]
struct ContentView: View {
@State var foos: FooArray = [
Foo(id: 1, num:0.0 ),
Foo(id: 2, num:0.1 ),
Foo(id: 3, num:0.2 ),
Foo(id: 4, num:0.3 )
]
@State private var revealFoos = true
var body: some View {
VStack {
Text("Foo")
.font(.title)
.bold()
Divider()
//DisclosureGroup("Foos", isExpanded: $revealFoos) {
FooTable(foos: foos)
//}
Spacer()
}
}
}
struct FooTable : View {
var foos: FooArray
@State private var sortOrder = [KeyPathComparator(\Foo.id, order: .reverse)]
var body: some View {
VStack {
Table(foos, sortOrder: $sortOrder) {
TableColumn("ID", value: \.id) { value in
Text(value.id.description)
}
TableColumn("Number", value: \.num) { value in
Text(value.num.description)
.frame(maxWidth: .infinity, alignment: .trailing)
}
}
}
}
}
PlaygroundPage.current.setLiveView(ContentView())