I'm trying to close my expandable list when I click one of the item in my list. But somehow it is not triggering. I don't know where I'm making mistake. For that I'm using isExpanded
Bool
and when I click other items in my list im making isExpanded = false
but its not working. Any idea?
struct SingleSelectionRow: View {
@Binding var selectSingle: Int
@Binding var selectedFilter: String?
var title: String
var isSelected: Bool
var childrenList: [FilterChildren]
@State var filterDetail: SortAndFilterData
@State var singleSelectedFilters: [String]
@State var isExpanded : Bool = false
var action: () -> Void
@State var onClick: Bool = false
var body: some View {
if selectSingle == 1 {
if childrenList.isEmpty == true {
Button(action: {
self.action()
isExpanded = false
print("İS EXPANDED İS \(isExpanded)")
}) {
Text(self.title.uppercased())
.font(.custom("DM Sans",size:15))
.foregroundColor(isSelected ? Color(red: 10 / 255, green: 207 / 255, blue: 131 / 255) : Color.black)
}
}
if childrenList.isEmpty == false {
DisclosureGroup(
isExpanded: $isExpanded,
content: {
ForEach(childrenList, id: \.id) { item in
Button(action: self.action) {
Text(item.name ?? "")
.font(.custom("DM Sans",size:15))
.frame(maxWidth: .infinity, alignment: .leading)
}
}
},
label: {
Text(self.title.uppercased())
.foregroundColor(isSelected ? Color(red: 10 / 255, green: 207 / 255, blue: 131 / 255) : Color.black)
}
)
.contentShape(Rectangle())
.onTapGesture {
withAnimation(.easeOut) {
isExpanded.toggle()
print("İS EXPANDED İS \(isExpanded)")
self.action()
}
}
}
}
}
}