Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Disabling animations when first loaded only
  • Loading branch information
mszylkowski committed Oct 28, 2021
commit 9e730166f74abc9db5261e3034bc4196f1694623
33 changes: 23 additions & 10 deletions extensions/amp-story/1.0/animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ const ANIMATE_IN_AFTER_ATTRIBUTE_NAME = 'animate-in-after';
const ANIMATE_IN_TIMING_FUNCTION_ATTRIBUTE_NAME = 'animate-in-timing-function';
/** @const {string} */
const ANIMATABLE_ELEMENTS_SELECTOR = `[${ANIMATE_IN_ATTRIBUTE_NAME}]`;
/** @const {string} selector for disabling animations on first page when first loaded */
const DISABLE_ANIMATIONS_FIRST_PAGE_SELECTOR =
'amp-story-page:first-of-type:not([i-amphtml-visited])';

/** @const {string} */
const DEFAULT_EASING = 'cubic-bezier(0.4, 0.0, 0.2, 1)';
Expand Down Expand Up @@ -545,12 +548,6 @@ export class AnimationManager {
/** @private @const */
this.builderPromise_ = this.createAnimationBuilderPromise_();

/** @private @const {bool} */
this.skipAnimations_ =
prefersReducedMotion(ampdoc.win) ||
(isExperimentOn(ampdoc.win, 'story-disable-animations-first-page') &&
matches(page, 'amp-story-page:first-of-type'));

/** @private {?Array<!AnimationRunner>} */
this.runners_ = null;

Expand All @@ -576,7 +573,7 @@ export class AnimationManager {
applyFirstFrameOrFinish() {
return Promise.all(
this.getOrCreateRunners_().map((runner) =>
this.skipAnimations_
this.skipAnimations_()
? runner.applyLastFrame()
: runner.applyFirstFrame()
)
Expand All @@ -595,7 +592,8 @@ export class AnimationManager {

/** Starts all entrance animations for the page. */
animateIn() {
if (this.skipAnimations_) {
console.log('skip animations', this.skipAnimations_());
if (this.skipAnimations_()) {
return;
}
this.getRunners_().forEach((runner) => runner.start());
Expand All @@ -617,15 +615,15 @@ export class AnimationManager {

/** Pauses all animations in the page. */
pauseAll() {
if (!this.runners_ || this.skipAnimations_) {
if (!this.runners_ || this.skipAnimations_()) {
return;
}
this.getRunners_().forEach((runner) => runner.pause());
}

/** Resumes all animations in the page. */
resumeAll() {
if (!this.runners_ || this.skipAnimations_) {
if (!this.runners_ || this.skipAnimations_()) {
return;
}
this.getRunners_().forEach((runner) => runner.resume());
Expand Down Expand Up @@ -821,6 +819,21 @@ export class AnimationManager {

return options;
}

/**
* Whether to skip the animations on the page, due to reduced motion or first page.
* @return {boolean}
*/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@private

skipAnimations_() {
return (
prefersReducedMotion(this.ampdoc_.win) ||
(isExperimentOn(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we're planning on launching this experiment, and we should not repurpose them it makes old data, dashboards, and documents very confusing.

this.ampdoc_.win,
'story-disable-animations-first-page'
) &&
matches(this.page_, DISABLE_ANIMATIONS_FIRST_PAGE_SELECTOR))
);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still disables animations on non transformed documents

}

/** Bus for animation sequencing. */
Expand Down