Sorin Lica
Sorin Lica

Reputation: 7686

Catch Tap gesture on Form in SwiftUI

struct ContentView: View {

    @State var text = ""
    var body: some View {
        Form {
            Button(action: {
                print("Button pressed")
            }) {
                Text("Button")
            }
        }.simultaneousGesture(TapGesture().onEnded( { print("tap") }))
    }
}

I need both Button' action and tap gesture on Form to be caught, but only print("tap") is executed. For a VStack works fine, but it seems the Form is a little bit special. Any idea ?

Upvotes: 2

Views: 1725

Answers (1)

Chris
Chris

Reputation: 8126

if you do it like this, you will get the button tap (but also the form tap). I don't know if this helps you.

@State var text = ""
var body: some View {
    Form {
        Button(action: {

        }) {
            Text("Button")
        }.onTapGesture {
            print("button")
        }
    }.onTapGesture {
        print("form")
    }    }
}

Upvotes: 0

Related Questions