Not sure what your "AnimatedButton
" struct looks like but this is mine from the HWS+ tutorial
import SwiftUI
protocol AnimatingButtonStyle: ButtonStyle {
init(animation: Double)
}
struct AnimatedButton<ButtonStyle: AnimatingButtonStyle, Content: View>: View {
let buttonStyle: ButtonStyle.Type // THE ORDER IS IMPORTANT FOR THE CALL
var animationSpeed = 5.0
let action: () -> Void
let label: () -> Content
@State private var animation = 0.0
var body: some View {
Button(action: action, label: label)
.buttonStyle(buttonStyle.init(animation: animation))
.onAppear {
withAnimation(Animation.easeOut(duration: self.animationSpeed).repeatForever(autoreverses: false)) {
self.animation = 1
}
}
}
}
Then you make the configuration eg
struct PulsingButtonStyle: AnimatingButtonStyle {
let animation: Double
func makeBody(configuration: Configuration) -> some View {
configuration.label
.padding()
.background(Color.blue)
.clipShape(Circle())
.foregroundColor(.white)
.padding(4)
.overlay(
Circle()
.stroke(Color.blue, lineWidth: 2)
.scaleEffect(CGFloat(1 + animation))
.opacity(1 - animation)
)
}
}
then when you use in your view
AnimatedButton(buttonStyle: PulsingButtonStyle.self, animationSpeed: 1, action: {
print("Pressed")
}) {
Image(systemName: "star")
}
This works fine on Xcode 12.1 fine, so think maybe your code not the same