Skip to content

Instantly share code, notes, and snippets.

@mishimay
Last active May 30, 2022 15:52
Show Gist options
  • Save mishimay/c17505e9943cc78447585648d28d91de to your computer and use it in GitHub Desktop.
Save mishimay/c17505e9943cc78447585648d28d91de to your computer and use it in GitHub Desktop.
import SwiftUI
struct ContentView: View {
var body: some View {
Button(action: {
}) {
Text("Button")
.padding()
.foregroundColor(.white)
.background(.blue)
.cornerRadius(12)
}
.buttonStyle(ShrinkButtonStyle())
}
struct ShrinkButtonStyle: ButtonStyle {
func makeBody(configuration: Self.Configuration) -> some View {
configuration.label
.scaleEffect(configuration.isPressed ? 0.95 : 1)
.animation(
// Tweak animation
configuration.isPressed ? .interactiveSpring(response: 0.3) : .spring(response: 0.8),
value: configuration.isPressed
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment