Shake Button
A reusable button component with various styles and states
Preview
Code
1import SwiftUI23struct ShakeButtonView: View {4 @State private var isShaking = false5 6 var body: some View {7 Button("Shake Me!") {8 withAnimation(.easeInOut(duration: 0.1).repeatCount(6, autoreverses: true)) {9 isShaking.toggle()10 }11 }12 .padding()13 .background(Color.blue)14 .foregroundColor(.white)15 .cornerRadius(10)16 .offset(x: isShaking ? -10 : 0)17 }18}1920struct ShakeButtonView_Previews: PreviewProvider {21 static var previews: some View {22 ShakeButtonView()23 }24}