use_animation_transition

Function use_animation_transition 

Source
pub fn use_animation_transition<Animated, T>(
    value: impl IntoReadable<T>,
    run: impl FnMut(T, T) -> Animated + 'static,
) -> UseAnimation<Animated>
where Animated: AnimatedValue, T: Clone + PartialEq + 'static,
Expand description

Create a transition animation that animates from the previous value to the current value.

This hook tracks the previous and current values of a reactive value and creates an animation that transitions between them when the value changes.

ยงExample

fn app() -> impl IntoElement {
    let color = use_state(|| Color::RED);
    let animation =
        use_animation_transition(color, |from: Color, to| AnimColor::new(from, to).time(500));

    rect()
        .background(&*animation.read())
        .width(Size::px(100.))
        .height(Size::px(100.))
}