Running into a problem on macOS 14.0/SwiftUI. In the code below, the first Section(isExpanded:) component works (expands) while the second doesn't. The one that works is the one where the Bool controlling expansion is referenced by another component. The one that doesn't is where the Bool controlling expansion isn't referenced.
Anybody know what's happening in this case or have a workaround (other than the one used in this example)?
@ObservedObject var foo: Foo
@State private var isExpanded_1 = true
@State private var isExpanded_2 = true
var body: some View {
VStack {
// This section's expansion works because isExpanded_1 is referenced by another component (Text).
Text("isSummaryExpanded = \(isExpanded_1.description)")
Section(isExpanded: $isExpanded_1) {
Text("Working section")
}
header: {
SummaryHeader(isSummaryExpanded: $isExpanded_1)
}
// This section's expansion doesn't work because isExpanded_2 isn't referenced anywhere else.
Section(isExpanded: $isExpanded_2) {
Text("Broken section")
}
header: {
SummaryHeader(isSummaryExpanded: $isExpanded_2)
}
Spacer()
}
}
}