I have a List
which acts like a form where you can enter values. It uses a custom View
struct SectionArea
to separate the various sections and cut down on code duplication, like this:
List {
SectionArea(title: "Section One", height: 176, horizontalPadding: 0, roundCorners: (0, 0, 0, 0)) {
VStack {
Button {
print("Pressed Button One")
fullScreenViewChoice = .optionOne
showSubView.toggle()
} label: {
HStack {
Text("Button One")
Spacer()
Image(systemName: "chevron.right")
}
}
.frame(height: 40)
Divider()
Button {
print("Pressed Button Two")
fullScreenViewChoice = .optionTwo
showSubView.toggle()
} label: {
HStack {
Text("Button Two")
Spacer()
Image(systemName: "chevron.right")
}
}
.frame(height: 40)
Divider()
}
}
}
.listStyle(.plain)
.listRowSpacing(0)
It works fine, but regardless of which button I press it always acts as though both buttons have been pressed. Say I press Button One
, the console will display:
Pressed Button One
Pressed Button Two
Can someone tell me where I'm going wrong here, please? Thanks!
EDIT: Actually, it doesn't look like it's because of the SectionArea
struct, because I've taken the code from there and wrapped it around the content directly, rather than using that struct, and it still does it.
I've removed everything and just put this:
List {
VStack {
ButtonOne
ButtonTwo
}
}
It still presses both buttons.