One way to think of these animations is to put yourself in SwiftUI's shoes.
Get a pencil and draw the struct's body when the animationAmount
is 1.0. Then draw the struct's body when the animationAmount
is 2.0. These are SwiftUI's starting and ending points.
SwiftUI then renders all of the inbetween frames ('tweening') for you. If your animation lasts 1/2 second, it might render 500 frames. If your animation lasts 6 seconds, it might render 50,000 frames. In each frame, SwiftUI gracefully changes the look of your struct. Each frame is rendered with slight changes to color, opacity, and scale.
From the beginning to the end, SwiftUI renders the entire animation sequence and captures the frames in an optimized internal video buffer. Because you added the .repeatForever()
modifier, SwiftUI replays the animations in this internal buffer over and over and over again. It was only rendered once, but the modifier ensures it is played on an endless loop.
And Vince is correct. Once the view appears in your app, the animationAmount
variable has changed to 2.0 and doesn't change again.
True Fact: I made up the term "optimized internal video buffer." I have no idea how the frames are rendered or stored. It's fast and efficient and easy to implement!