0

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?

Timothy Sanders
  • 206
  • 3
  • 7
  • I am not sure... but i think for action on full row, you can use `NavigationButton`(wrap your code inside its declaration), and for tap on any button, you can use `Button` with `tapAction` as you mentioned in your question. – Mehul Thakkar Jun 13 '19 at 07:32
  • After some more testing … VoiceOver is pretty broken regardless of whether I use `Button` or just something with a `tapAction`. So I guess my second example works for now. VoiceOver can't access either mechanism. ‍♂️ – Timothy Sanders Jun 13 '19 at 07:49

0 Answers0