How can i disable the default Button click animation in SwiftUI and Swift 5? I tried to add .animation(.nil)
to the button, without any changes.
I know that you can do the following:
Button(action: {}) { Capsule() }
.buttonStyle(NoAnim())
struct NoAnim: ButtonStyle {
func makeBody(configuration: Self.Configuration) -> some View {
configuration.label
}
Does anybody know a smarter way?
If I correctly understood your question, then it is better to use just
Capsule()
.onTapGesture {
// << action here !!
}
iOS 13.x, Swift 5.
So you want something that is clickable, but not a button. Just use a label with a onTapGesture on it and then you can add whatever animation you like.
Alternatively you could use the onDrag gesture like this too. This will update the dragLocation as soon as you touch it. So it is like touch event. It also doesn't have any animation liked to it either. That you can add if you so wish.
Text("Hello World")
.accessibility(label: Text("Button"))
.gesture(
DragGesture(minimumDistance: 5, coordinateSpace: .global)
.onChanged { value in
self.dragLocation = value.location
}
.onEnded { _ in
self.dragLocation = .zero
}
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With