Skip to content

Commit

Permalink
feat: OnDepsChange::Rerun for use_animation
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 committed Jan 12, 2025
1 parent d96f0b4 commit ebeffe1
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions crates/hooks/src/use_animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ pub enum OnDepsChange {
#[default]
Reset,
Finish,
Rerun,
}

/// Animate your elements. Use [`use_animation`] to use this.
Expand Down Expand Up @@ -776,6 +777,23 @@ pub fn use_animation<Animated: AnimatedValue>(
}
});

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
}

Expand Down Expand Up @@ -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());
}
_ => {}
}
}
});

Expand Down

0 comments on commit ebeffe1

Please sign in to comment.