Created
March 19, 2025 21:24
-
-
Save maxamly/617d55b2afb23c0d8b73eb4f915c9c3a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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