Default button action does not trigger in conjunction with onTapGesture.

I implemented an animated button modifier like this:

Button(“Text”) {
Print(“default action”)
}.modifier(OnTouchDownGestureModifier())

Inside of OnTouchDownGestureModifier, it calls onTapGesture to trigger animation.

func body(content: Content) -> some View {
        content
            .onTapGesture {

However, default action does not trigger because of onTapGesture.

I tried manually calling the default action in the modifier, but it seems there is no such things.

Could anyone suggest any workaround with this?

Answered by tennaaaaa in 783365022

I just had to detect isPressed state in ButtonStyle and trigger the animation. It was pretty simple..

Accepted Answer

I just had to detect isPressed state in ButtonStyle and trigger the animation. It was pretty simple..

Default button action does not trigger in conjunction with onTapGesture.
 
 
Q