Thanks OOPer!
Turns out all I needed was to add the onChange you suggested - needing both the onAppear and onChange. So the BackgroundView looks like this:
swift
struct BackgroundView: View {
var status: String = "0"
@State private var isAnimating: Bool = false
var body: some View {
ZStack {
Group {
Image(systemName: "\(status).circle.fill")
.resizable()
.scaledToFit()
.frame(width: 220)
.foregroundColor(.red)
}
.scaleEffect(isAnimating ? 1.0 : 0, anchor: .top)
}
.animation(Animation.easeOut(duration: 0.4), value: isAnimating)
.onAppear(perform: {
print("appear: \(status)")
isAnimating = true
})
.onChange(of: status) { _ in
print("change: \(status)")
isAnimating = false
withAnimation(Animation.easeOut(duration: 0.4)) {
isAnimating = true
}
}
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: