Some Examples » 29. Cycling parent and child variants
29. Cycling parent and child variants
Another example of automatic animation propagation with variants
, here in combination with useCycle()
.
Code component
Code overrides
When you tap the Switch
, it does a cycle
to the next variant label. And the children (Background()
and Knob()
overrides) will follow along, just because they have the same variant labels: "off"
and "on"
.
Note that the override for the parent frame, Switch()
, doesn’t even have an animation.
By the way, I used the onTapStart()
event so that the animation already starts when you press down.