0

I'm trying to set up a carousel list on WatchOS. Each row in the list has a Toggle in it. I want the user to have to tap the Toggle itself to interact with it; however, the list row seems to be passing any taps anywhere on it to the toggle. This happens for Buttons as well. How can I disable this behavior?

I wrote the following sample View to illustrate what's happening:

struct TestView: View {
    @State var value:Bool = false
    var body: some View {
        List{
            Toggle("test", isOn: $value)
            Button("test"){
                print("Button pressed")
            }
        }
    }
}

This yields the following output:
TestView

Whenever a tap is registered anywhere in the first list row, the Toggle is switched. Whenever a tap is registered anywhere in the second list row, the button's action (printing to the console) is triggered. I would like it such that the Toggle only registers a tap when it itself is tapped. I tried adding .onTapGesture{} , which works partially, but doesn't stop long presses from getting through. Adding .onLongPressGesture{} breaks scrolling, making it not a viable option either.

Any advice?

tattar8
  • 11
  • 2

0 Answers0