to add animation to some view when it changes, add .animation(.default, value: someVariable)
.
This will apply the .default
animation as an implicit animation, whenever the value of that variable changes.
Alternatively, you can add the .animation()
modifier when you change the value of the variable. This is called “animated binding changes”.
For example in a stepper you could do Stepper("Scale amount", value: $animationAmount.animation(), in: 1...10)
You don’t need to specify what variable to watch with this style of course, because you’ve stuck the animation on the variable itself
Using this method, the animation does NOT run if you change the variable somewhere else.
Or we can create an explicit animation on some state change. For example, a button’s method could be withAnimation { animationAmount += 1 }