Advertisement
bbcqx

Untitled

Mar 19th, 2025
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.06 KB | None | 0 0
  1. import SwiftUI
  2.  
  3. struct ScaledButtonStyleTest: ButtonStyle {
  4.   func makeBody(configuration: Configuration) -> some View {
  5.     configuration.label
  6.       .scaleEffect(configuration.isPressed ? 0.2 : 1.0)
  7.       .animation(
  8.         .spring(response: 0.2, dampingFraction: 1),
  9.         value: configuration.isPressed
  10.       )
  11.   }
  12. }
  13.  
  14. struct TestPressView: View {
  15.   @State private var selection: Int = 0
  16.  
  17.   var body: some View {
  18.     VStack(spacing: 20) {
  19.       TabView(selection: $selection) {
  20.         ForEach(0..<5) { index in
  21.           Button("Animation doesn't work") {
  22.             print("Button tapped 1")
  23.           }
  24.           .buttonStyle(ScaledButtonStyleTest())
  25.         }
  26.       }
  27.       .tabViewStyle(.page(indexDisplayMode: .never))
  28.       .frame(maxWidth: .infinity, maxHeight: 100)
  29.  
  30.       Button("Animation does work") {
  31.         print("Button tapped 2")
  32.       }
  33.       .buttonStyle(ScaledButtonStyleTest())
  34.     }
  35.     .padding()
  36.   }
  37. }
  38.  
  39. struct Playground: View {
  40.   var body: some View {
  41.     TestPressView()
  42.   }
  43. }
  44.  
  45. #Preview {
  46.   Playground()
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement