I have a form with a number of items, and one of the rows I want to have multiple buttons. However, when one is tapped, the entire row lights up, and all the actions of all buttons in the rows are called.
How can I have buttons in a Form row that don't highlight the entire row, and that only have their own action called?
(also: how can I make sure the entire row does not become tappable?)
Example code: in the following example, even though from reading through you'd expect that once you tap one button, the other would be disabled, in fact, both buttons are disabled, since both button actions are called.
Example screenshots: Here I tapped "A!" only, yet the entire row lights up, and both button actions are called

import SwiftUI
struct TwoButtonsInAFormRowView: View {
@State private var buttonADisabled = false
@State private var buttonBDisabled = false
var body: some View {
Form {
ForEach(0..<5) { _ in
HStack {
Text("We have many rows like this....")
Spacer()
TextField("Like this", text: .constant("value"))
.multilineTextAlignment(.trailing)
}
}
HStack {
Text("Tap one (and only one) button")
Spacer()
Button(action: {
self.buttonBDisabled = true
}) {
Text("A!")
}
.disabled(self.buttonADisabled)
Button(action: {
self.buttonADisabled = true
}) {
Text("B!")
}
.disabled(self.buttonBDisabled)
}
}
}
}
#if DEBUG
struct TwoButtonsInAFormRowViewPreviews: PreviewProvider {
static var previews: some View {
return TwoButtonsInAFormRowView()
.previewLayout(.sizeThatFits)
}
}
#endif