Skip to content

Commit

Permalink
🐛 Animation improvements (ampproject#23322)
Browse files Browse the repository at this point in the history
* animation improvements

* fix types

* welp...

* use scheduleWait_ var instead
  • Loading branch information
Enriqe authored Jul 15, 2019
1 parent 50f9187 commit ef9347b
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions extensions/amp-story/1.0/animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,12 @@ class AnimationRunner {
* !../../amp-animation/0.1/web-animations.Builder
* >} webAnimationBuilderPromise
* @param {!../../../src/service/vsync-impl.Vsync} vsync
* @param {!../../../src/service/timer-impl.Timer} timer
* @param {!AnimationSequence} sequence
*/
constructor(
page,
animationDef,
webAnimationBuilderPromise,
vsync,
timer,
sequence
) {
constructor(page, animationDef, webAnimationBuilderPromise, vsync, sequence) {
/** @private @const */
this.page_ = page;

/** @private @const */
this.timer_ = timer;

/** @private @const */
this.vsync_ = vsync;

Expand Down Expand Up @@ -204,6 +193,7 @@ class AnimationRunner {
return this.keyframes_.then(keyframes => ({
keyframes,
target: this.target_,
delay: `${this.delay_}ms`,
duration: `${this.duration_}ms`,
easing: this.easing_,
fill: 'forwards',
Expand Down Expand Up @@ -249,10 +239,6 @@ class AnimationRunner {
promise = promise.then(() => this.sequence_.waitFor(startAfterId));
}

if (this.delay_) {
promise = promise.then(() => this.timer_.promise(this.delay_));
}

return promise;
}

Expand Down Expand Up @@ -283,13 +269,25 @@ class AnimationRunner {

/** Pauses the animation. */
pause() {
// Animation hasn't started yet since it's waiting for a sequenced
// animation.
if (this.scheduledWait_ !== null) {
return;
}

if (this.runner_) {
devAssert(this.runner_).pause();
}
}

/** Resumes the animation. */
resume() {
// Animation hasn't started yet since it's waiting for a sequenced
// animation.
if (this.scheduledWait_ !== null) {
return;
}

if (this.runner_) {
devAssert(this.runner_).resume();
}
Expand Down Expand Up @@ -429,9 +427,6 @@ export class AnimationManager {
/** @private @const */
this.vsync_ = Services.vsyncFor(this.ampdoc_.win);

/** @private @const */
this.timer_ = Services.timerFor(this.ampdoc_.win);

/** @private @const */
this.builderPromise_ = this.createAnimationBuilderPromise_();

Expand Down Expand Up @@ -535,7 +530,6 @@ export class AnimationManager {
animationDef,
devAssert(this.builderPromise_),
this.vsync_,
this.timer_,
this.sequence_
);
}
Expand Down

0 comments on commit ef9347b

Please sign in to comment.