Skip to content

Instantly share code, notes, and snippets.

@maxamly
Created March 19, 2025 21:19
Show Gist options
  • Save maxamly/c3512f694cd286b4da2028e742db40a4 to your computer and use it in GitHub Desktop.
Save maxamly/c3512f694cd286b4da2028e742db40a4 to your computer and use it in GitHub Desktop.
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 {
ScrollView(.horizontal) {
HStack (spacing: 0){
ForEach(0..<5) { index in
Button("Animation doesn't work \(index)") {
print("Button tapped 1")
}
.buttonStyle(ScaledButtonStyleTest())
.containerRelativeFrame(.horizontal)
}
}
}
.scrollTargetBehavior(.paging)
.scrollIndicators(.hidden)
}
}
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