Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SarahAlsharif/30bc4f780664decee18687435107c61c to your computer and use it in GitHub Desktop.
Save SarahAlsharif/30bc4f780664decee18687435107c61c to your computer and use it in GitHub Desktop.
struct NeumorphicButtonStyle: ButtonStyle {
@State var opacity : CGFloat = 1
@State var opacityOp : CGFloat = 0
@State var shadowRadiusXY : CGFloat = 3
@State var scale : CGFloat = 1
let width : CGFloat
let cornerRadius : CGFloat
func makeBody(configuration: Self.Configuration) -> some View {
configuration.label
.padding()
.frame(width: width)
.foregroundColor(.primary)
.background(NeuButtonBackgroundView(cornerRadius: cornerRadius, opacity: $opacity, opacityOp: $opacityOp, shadowRadiusXY: $shadowRadiusXY))
.scaleEffect(scale)
.onChange(of: configuration.isPressed) { newValue in
if (!configuration.isPressed) {
withAnimation(.spring(dampingFraction: 0.5).speed(2)) {
opacity = 0
scale = 0.95
opacityOp = 1
shadowRadiusXY = 0
}
} else {
withAnimation(.spring(dampingFraction: 0.5).speed(2)) {
opacity = 1
scale = 1
opacityOp = 0
shadowRadiusXY = 3
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment