From ebeffe15136257b51380c72168710629f53ff76b Mon Sep 17 00:00:00 2001 From: marc2332 Date: Sun, 12 Jan 2025 19:24:36 +0100 Subject: [PATCH] feat: `OnDepsChange::Rerun` for `use_animation` --- crates/hooks/src/use_animation.rs | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/crates/hooks/src/use_animation.rs b/crates/hooks/src/use_animation.rs index 9f5718367..f9e3f17eb 100644 --- a/crates/hooks/src/use_animation.rs +++ b/crates/hooks/src/use_animation.rs @@ -497,6 +497,7 @@ pub enum OnDepsChange { #[default] Reset, Finish, + Rerun, } /// Animate your elements. Use [`use_animation`] to use this. @@ -776,6 +777,23 @@ pub fn use_animation( } }); + use_memo(move || { + let context = context.read(); + if *has_run_yet.peek() + { + match context.conf.on_deps_change { + OnDepsChange::Finish => { + animation.finish() + } + OnDepsChange::Rerun => { + let last_direction = *animation.last_direction.peek(); + animation.run(last_direction); + } + _ => {} + } + } + }); + animation } @@ -810,8 +828,17 @@ where use_memo(move || { let context = context.read(); - if *has_run_yet.peek() && context.conf.on_deps_change == OnDepsChange::Finish { - animation.finish() + if *has_run_yet.peek() + { + match context.conf.on_deps_change { + OnDepsChange::Finish => { + animation.finish() + } + OnDepsChange::Rerun => { + animation.run(*animation.last_direction.peek()); + } + _ => {} + } } });