Say I have the following code(A):
struct ItemListView: View {
@State private var items: [Item]
var body: some View {
List(items, id: \.self) { item in
DisclosureGroup(item.name) {
item.itemDescription
}
} // List
} // body
}
compared with(B):
struct ItemListView: View {
@State private var items: [Item]
var body: some View {
List {
ForEach(items, id: \.self) { item in
DisclosureGroup(item.name) {
item.itemDescription
}
} // ForEach
} // List
} // body
}
In code A, when I tap on the disclosure indicator the itemDescription appears to the right of the name where as in the B the itemDescription appears below where the item's name is. Why is this? When should I use List(items, ...) vs. List { ForEach(items, ...) }?
EDIT: If this helps anyone, after placing the DisclosureGroup in an HStack, the same thing happens as in Code A:
HStack {
DisclosureGroup(item.name) {
Text(item.itemDescription)
}
Spacer()
}
.onTapGesture {
print("PRINT")
}
Code A:
Code B: