I'm struggling to implement a flash animation in SwiftUI.
Generally animations animate from one value to another. I'd like to animate from normal to the flashed state and then back to normal, each time the data shown by the view changes. The "flashed state" could be transparent, or a white background, or it could be a scale change for a pulse effect, or something.
Example:
struct MyView: View
{
let value: String;
var body: some View {
ZStack {
Capsule() .fill(Color.green);
Text(value);
}
};
};
Each time value
changes, I'd like the colour of the capsule to quickly animate from green to white and back to green.
I feel this should be easy - am I missing something?
For bonus points:
-
I'd like the
Text
to change to its new value at the midpoint of the animation, i.e. when the white text is invisible on the white background. -
I'd like to get the flash effect whenever I have a new value even if the new value is equal to the old value, if you see what I mean.