pub fn use_motion<T: Animatable + Send + 'static>(
initial: T,
) -> impl AnimationManager<T>Expand description
Creates an animation manager that continuously updates a motion state.
This function initializes a motion state with the provided initial value and spawns an asynchronous loop that updates the animation state based on the elapsed time between frames. When the animation is running, it updates the state using the calculated time delta and dynamically adjusts the update interval to optimize CPU usage; when the animation is inactive, it waits longer before polling again.
ยงExample
use dioxus_motion::prelude::*;
use dioxus::prelude::*;
fn app() -> Element {
let mut value = use_motion(0.0f32);
// Animate to 100 with spring physics
value.animate_to(
100.0,
AnimationConfig::new(AnimationMode::Spring(Spring::default()))
);
rsx! {
div {
style: "transform: translateY({value.get_value()}px)",
"Animated content"
}
}
}