I'm trying to change the colour of my animation based on the state of something. The colour change works but it animates the previous (orange) colour with it. I can't quite work out why both colours are showing. Any ideas?
struct PulsatingView: View { var state = 1 func colourToShow() -> Color { switch state { case 0: return Color.red case 1: return Color.orange case 2: return Color.green default: return Color.orange } } @State var animate = false var body: some View { VStack { ZStack { Circle().fill(colourToShow().opacity(0.25)).frame(width: 40, height: 40).scaleEffect(self.animate ? 1 : 0) Circle().fill(colourToShow().opacity(0.35)).frame(width: 30, height: 30).scaleEffect(self.animate ? 1 : 0) Circle().fill(colourToShow().opacity(0.45)).frame(width: 15, height: 15).scaleEffect(self.animate ? 1 : 0) Circle().fill(colourToShow()).frame(width: 6.25, height: 6.25) } .onAppear { self.animate.toggle() } .animation(Animation.easeInOut(duration: 1.5).repeatForever(autoreverses: true)) } } } 