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
:
var body: some View {
NavigationView {
List {
NavigationLink("Button") {
Text("Next")
}
}
}
}
And the issue you reported is because the buttonStyle
is automatic
when you use it in a list
. You can change it to anything but the automatic
. like:
List {
Button(action: {}, label: {
Text("Button")
})
}
.buttonStyle(.borderless) // 👈 Here