Post

Replies

Boosts

Views

Activity

Open/Close DisclosureGroup
Hi, In Xcode 12.01 I am working on a View with an unknown number of DisclosureGroups in a List. I want to close any open DisclosureGroup when the user expands DisclosureGroups. For example here in this test code I have 100 DisclosureGroups in List and the code will close any open. import SwiftUI struct TestView: View {     @State var selectedStrength = 0     @State var expaned = Array(repeating: false, count: 100)     var strengths = Array(repeating: "Test", count: 100)     var body: some View {         List {             ForEach(0 ..< strengths.count, id: \.self) { strIndex in                 DisclosureGroup(isExpanded: $expaned[strIndex], content: {                     Text("Group open \(strIndex)")                 } , label: {                     Text("Group \(strIndex)")                 }).onChange(of: expaned[strIndex]) { _ in                     if expaned[strIndex] {                         for index in expaned.indices {                             if index != strIndex {                                 expaned[index] = false                             }                         }                     }                 }             }         }     } } But how to handle this if the number number of DisclosureGroups not known?
2
0
2.3k
Oct ’21