I'm trying to have a list (what would be a UITableView
in UIKit
), where the cells both have multiple buttons and can transition to a detailed view. When I was developing the row view (what would be a cell in UIKit
) the buttons worked fine. But as soon as I wrap the row in a List
or a ForEach
tapping anywhere in the row also fires all button actions simultaneously.
After a lot of messing around, I found that Button
seems to opt-in to this cooperative, non-exclusive sort of mode. So for example:
Button(action: { self.timerData.reset() }) {
Text("Reset")
.bold()
.foregroundColor(.red)
}
will fire for ANY tap on the row. I can change this to explicitly be a Text
"label" with a tapAction
and it starts consuming taps on it, but not firing on taps on the larger row.
Text("Reset")
.bold()
.foregroundColor(.red)
.tapAction {self.timerData.reset()}
So this is great … until I test with VoiceOver on. Accessibility no longer sees it as a button, and the whole row is one fused item from an accessibility perspective.
My best guess is that I need to mess around with something inside the API about composing gestures (see https://developer.apple.com/documentation/swiftui/gestures/composing_swiftui_gestures ), but nothing there seems to jump out at me, and I don't think they went into this sort of depth in any of the WWDC talks I've watched.
Does anybody know how to specify that I want child buttons to only fire when they are specifically tapped, and then specify a more generic action to fire when the row is tapped outside of any active button?