Pseudo-code:
PhaseAnimator([false,true], trigger: foo) { flash in
ZStack {
Capsule()
.foregroundStyle(flash ? .red : .green)
Canvas { context, size in
context.draw(image: Image(name: "foo"), toFitRect: some_rectangle);
context.draw(text: Text("foo"), toFitRect: another_rectangle);
}
.foregroundStyle(flash ? .black : .white)
}
} animation: { flash in
return .linear(duration: 0.5);
}
The Capsule's colour animates, but the Canvas's doesn't. The Canvas drawing code is only ever called with flash==false
.
What do I have to do to the Canvas so that it redraws with the intermediate colours during the animation?