With ButtonStyle, the disabled modifier does not seem to work, we need to use allowsHitTesting.
import SwiftUI
struct ActionButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
HStack {
Text("Button")
}
.padding()
.disabled(true) // does not work
.allowsHitTesting(false)
}
}
We need to call disabled outside, after buttonStyle. In case we have onTapGesture on the entire view, touching on that disabled button will also trigger our whole view action, which is not what we want.
With
ButtonStyle
, thedisabled
modifier does not seem to work, we need to useallowsHitTesting
.We need to call
disabled
outside, afterbuttonStyle
. In case we haveonTapGesture
on the entire view, touching on that disabled button will also trigger our whole view action, which is not what we want.Another way is to overlay with a dummy view with a dummy tap gesture to obscure the action
So that we have