1use dioxus::prelude::*;
2use futures::{pin_mut, StreamExt};
3use interpolation::Lerp;
4use std::time::Duration;
5
6mod controller;
7pub use controller::request_animation_frame;
8
9mod spring;
10pub use spring::spring;
11
12mod use_animated;
13pub use use_animated::use_animated;
14
15mod use_spring;
16pub use use_spring::use_spring;
17
18mod use_spring_signal;
19pub use use_spring_signal::use_spring_signal;
20
21mod use_spring_ref;
22pub use use_spring_ref::{use_spring_ref, UseSpringRef};
23
24pub fn use_on_spring<V>(from: V, to: V, duration: Duration, f: impl FnMut(V) + 'static)
25where
26 V: Lerp<Scalar = f32> + Clone + 'static,
27{
28 let mut cell = Some((from, to, f));
29 use_future(move || {
30 let (from, to, mut f) = cell.take().unwrap();
31 async move {
32 let spring = spring(from, to, duration);
33 pin_mut!(spring);
34
35 while let Some(val) = spring.next().await {
36 f(val);
37 }
38 }
39 });
40}