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’ll 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 all commits
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
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,6 +21,7 @@
"story-ad-auto-advance": 1,
"story-ad-placements": 1,
"story-load-first-page-only": 0.1,
"story-disable-animations-first-page": 0.1,
"amp-story-page-attachment-ui-v2": 1,
"amp-sticky-ad-to-amp-ad": 0
}
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.1,
"story-load-first-page-only": 0.1,
"amp-story-page-attachment-ui-v2": 1,
"amp-sticky-ad-to-amp-ad": 0
Expand Down
9 changes: 9 additions & 0 deletions extensions/amp-story/1.0/amp-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {CSS} from '../../../build/amp-story-1.0.css';
import {CommonSignals} from '#core/constants/common-signals';
import {EventType, dispatch} from './events';
import {Gestures} from '../../../src/gesture';
import {prefersReducedMotion} from '#core/dom/media-query-props';
import {HistoryState, getHistoryState, setHistoryState} from './history';
import {InfoDialog} from './amp-story-info-dialog';
import {Keys} from '#core/constants/key-codes';
Expand Down Expand Up @@ -468,6 +469,14 @@ export class AmpStory extends AMP.BaseElement {
'story-load-first-page-only'
);
}
if (
isExperimentOn(this.win, 'story-disable-animations-first-page') ||
prefersReducedMotion(this.win)
) {
Services.performanceFor(this.win).addEnabledExperiment(
'story-disable-animations-first-page'
);
}
if (isExperimentOn(this.win, 'story-load-inactive-outside-viewport')) {
Services.performanceFor(this.win).addEnabledExperiment(
'story-load-inactive-outside-viewport'
Expand Down
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