Split animation cancellation from update_style_for_animation

`update_style_for_animation` previously handled both canceling defunct
animations and also updating style to reflect current animation state.
This change splits those two concerns because we want to start handling
replaced or canceled animations and finished animations in two different
places.

This is a refactor, so ideally it shouldn't change any behavior.
This commit is contained in:
Martin Robinson 2020-04-30 10:59:56 +02:00
parent 3bedd44026
commit 0ab4260d6b
3 changed files with 128 additions and 121 deletions

View file

@ -128,17 +128,16 @@ pub fn handle_running_animations(
let mut running_animations =
std::mem::replace(&mut animation_state.running_animations, Vec::new());
for mut running_animation in running_animations.drain(..) {
let still_running = !running_animation.is_expired() &&
match running_animation {
Animation::Transition(_, started_at, ref property_animation) => {
now < started_at + (property_animation.duration)
},
Animation::Keyframes(_, _, _, ref mut state) => {
// This animation is still running, or we need to keep
// iterating.
now < state.started_at + state.duration || state.tick()
},
};
let still_running = match running_animation {
Animation::Transition(_, started_at, ref property_animation) => {
now < started_at + (property_animation.duration)
},
Animation::Keyframes(_, _, _, ref mut state) => {
// This animation is still running, or we need to keep
// iterating.
now < state.started_at + state.duration || state.tick()
},
};
// If the animation is still running, add it back to the list of running animations.
if still_running {
@ -165,9 +164,8 @@ pub fn handle_cancelled_animations(
Animation::Transition(_, _, ref property_animation) => {
send_transition_event(property_animation, TransitionEventType::TransitionCancel)
},
Animation::Keyframes(..) => {
warn!("Got unexpected animation in finished transitions list.")
},
// TODO(mrobinson): We should send animationcancel events.
Animation::Keyframes(..) => {},
}
}
}