I found this article regarding the same problem as I have:
Spinner animation starts bouncing once the view is updated
However, the best solution given does not appear to work in my case. It could well be I have missed something in the solution, but I cannot see anything!
struct OscillatingTextView: View
{
@State var doAnimation = false
var text: String
var animation: Animation {
Animation.easeInOut(duration: 1.0)
.repeatForever(autoreverses: true)
}
var body: some View {
HStack{
ForEach(Array(text), id: \.self)
{ letter in
Text(String(letter))
.rotationEffect(Angle.degrees(doAnimation ? 30:-30))
.animation(doAnimation ? animation : .default, value: doAnimation) //as advised in Asperi solution
}
.font(.largeTitle)
}
.onAppear()
{
doAnimation.toggle()
}
}
}