Skip to content

Commit

Permalink
fix: Last frame of animations was not always applied (#798)
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 authored Jul 16, 2024
1 parent c3821a3 commit 8ad268b
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions crates/hooks/src/use_animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,17 @@ impl AnimatedValue for AnimColor {
match direction {
AnimDirection::Forward => {
index > self.time.as_millis() as i32
&& self.value.r() >= self.destination.r()
&& self.value.g() >= self.destination.g()
&& self.value.b() >= self.destination.b()
&& self.value.a() >= self.destination.a()
&& self.value.r() == self.destination.r()
&& self.value.g() == self.destination.g()
&& self.value.b() == self.destination.b()
&& self.value.a() == self.destination.a()
}
AnimDirection::Reverse => {
index > self.time.as_millis() as i32
&& self.value.r() <= self.origin.r()
&& self.value.g() <= self.origin.g()
&& self.value.b() <= self.origin.b()
&& self.value.a() >= self.origin.a()
&& self.value.r() == self.origin.r()
&& self.value.g() == self.origin.g()
&& self.value.b() == self.origin.b()
&& self.value.a() == self.origin.a()
}
}
}
Expand Down Expand Up @@ -524,6 +524,14 @@ impl<Animated: PartialEq + Clone + 'static> UseAnimator<Animated> {
let is_finished = values
.iter()
.all(|value| value.peek().is_finished(index, direction));

// Advance the animations
for value in values.iter_mut() {
value.write().advance(index, direction);
}

prev_frame = Instant::now();

if is_finished {
if OnFinish::Reverse == on_finish {
// Toggle direction
Expand All @@ -544,13 +552,6 @@ impl<Animated: PartialEq + Clone + 'static> UseAnimator<Animated> {
}
}
}

// Advance the animations
for value in values.iter_mut() {
value.write().advance(index, direction);
}

prev_frame = Instant::now();
}

is_running.set(false);
Expand Down

0 comments on commit 8ad268b

Please sign in to comment.