Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement