Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃殌 [Story performance] Disable animations in first page under experiment #35356

Merged
merged 6 commits into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions build-system/global-configs/canary-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
"story-ad-auto-advance": 1,
"story-ad-placements": 1,
"story-load-first-page-only": 0.1,
"story-disable-animations-first-page": 0.05,
mszylkowski marked this conversation as resolved.
Show resolved Hide resolved
"amp-story-page-attachment-ui-v2": 1
}
1 change: 1 addition & 0 deletions build-system/global-configs/prod-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"amp-consent-granular-consent": 1,
"amp-cid-backup": 1,
"story-ad-placements": 0.01,
"story-disable-animations-first-page": 0.05,
"story-load-first-page-only": 0.1,
"amp-story-page-attachment-ui-v2": 1
}
20 changes: 14 additions & 6 deletions extensions/amp-story/1.0/animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ import {escapeCssSelectorIdent} from '#core/dom/css-selectors';
import {getChildJsonConfig} from '../../../src/json';
import {map, omit} from '#core/types/object';
import {prefersReducedMotion} from '#core/dom/media-query-props';
import {scopedQuerySelector, scopedQuerySelectorAll} from '#core/dom/query';
import {
matches,
scopedQuerySelector,
scopedQuerySelectorAll,
} from '#core/dom/query';
import {setStyles} from '#core/dom/style';
import {timeStrToMillis, unscaledClientRect} from './utils';
import {isExperimentOn} from '#experiments';

const TAG = 'AMP-STORY';

Expand Down Expand Up @@ -554,7 +559,10 @@ export class AnimationManager {
this.builderPromise_ = this.createAnimationBuilderPromise_();

/** @private @const {bool} */
this.prefersReducedMotion_ = prefersReducedMotion(ampdoc.win);
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 @@ -581,7 +589,7 @@ export class AnimationManager {
applyFirstFrameOrFinish() {
return Promise.all(
this.getOrCreateRunners_().map((runner) =>
this.prefersReducedMotion_
this.skipAnimations_
? runner.applyLastFrame()
: runner.applyFirstFrame()
)
Expand All @@ -600,7 +608,7 @@ export class AnimationManager {

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

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

/** Resumes all animations in the page. */
resumeAll() {
if (!this.runners_ || this.prefersReducedMotion_) {
if (!this.runners_ || this.skipAnimations_) {
return;
}
this.getRunners_().forEach((runner) => runner.resume());
Expand Down