My code is like this:
List {
Button(action: {}, label: {
Text("Button")
})
Button(action: {}, label: {
Text("Button")
})
}
when click button, it has none animation, it's not change the opacity, this not change backgroud color. But when press button, the backgroud color is changed. this result is:
The effect I except is click button and backgroud color changed immediately, like this:
I try to set buttonStyle by using code
struct clickButton: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.background(configuration.isPressed ? Color.gray : Color.white)
}
}
but the result is terrible.
The second image you provided is the default behavior of the
NavigationLink
:And the issue you reported is because the
buttonStyle
isautomatic
when you use it in alist
. You can change it to anything but theautomatic
. like: