Skip to content

Commit

Permalink
fix: Manually drop previous animated values when the run callback reruns
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 committed Jan 12, 2025
1 parent 2e458e1 commit 538ef3a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions crates/hooks/src/use_animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,11 +753,16 @@ pub fn use_animation<Animated: AnimatedValue>(
let has_run_yet = use_signal(|| false);
let task = use_signal(|| None);
let last_direction = use_signal(|| AnimDirection::Reverse);
let mut prev_value = use_signal::<Option<Signal<Animated>>>(|| None);

let context = use_memo(move || {
if let Some(prev_value) = prev_value.take() {
prev_value.manually_drop();
}
let mut conf = AnimConfiguration::default();
let value = run(&mut conf);
let value = Signal::new(value);
prev_value.set(Some(value));
Context { value, conf }
});

Expand Down Expand Up @@ -791,11 +796,16 @@ where
let has_run_yet = use_signal(|| false);
let task = use_signal(|| None);
let last_direction = use_signal(|| AnimDirection::Reverse);
let mut prev_value = use_signal::<Option<Signal<Animated>>>(|| None);

let context = use_memo(use_reactive(deps, move |deps| {
if let Some(prev_value) = prev_value.take() {
prev_value.manually_drop();
}
let mut conf = AnimConfiguration::default();
let value = run(&mut conf, deps);
let value = Signal::new(value);
prev_value.set(Some(value));
Context { value, conf }
}));

Expand Down

0 comments on commit 538ef3a

Please sign in to comment.