Skip to content

Instantly share code, notes, and snippets.

@maxamly
Created March 19, 2025 21:24
import SwiftUI
struct ScaledButtonStyleTest: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.scaleEffect(configuration.isPressed ? 0.2 : 1.0)
.animation(
.spring(response: 0.2, dampingFraction: 1),
value: configuration.isPressed
)
}
}
struct TestPressView: View {
@State private var selection: Int = 0
var body: some View {
VStack(spacing: 20) {
TabView(selection: $selection) {
ForEach(0..<5) { index in
Button("Animation doesn't work") {
print("Button tapped 1")
}
.buttonStyle(ScaledButtonStyleTest())
}
}
.tabViewStyle(.page(indexDisplayMode: .never))
.frame(maxWidth: .infinity, maxHeight: 100)
Button("Animation does work") {
print("Button tapped 2")
}
.buttonStyle(ScaledButtonStyleTest())
}
.padding()
}
}
struct Playground: View {
var body: some View {
TestPressView()
}
}
#Preview {
Playground()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment