-
Notifications
You must be signed in to change notification settings - Fork 4.1k
🐛 [Story performance] Disabling animations on initial page when first loaded #36668
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
Changes from 1 commit
9e73016
df7609a
a87b850
f9e3ef4
a2637df
eae03ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)'; | ||
|
|
@@ -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; | ||
|
|
||
|
|
@@ -576,7 +573,7 @@ export class AnimationManager { | |
| applyFirstFrameOrFinish() { | ||
| return Promise.all( | ||
| this.getOrCreateRunners_().map((runner) => | ||
| this.skipAnimations_ | ||
| this.skipAnimations_() | ||
| ? runner.applyLastFrame() | ||
| : runner.applyFirstFrame() | ||
| ) | ||
|
|
@@ -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()); | ||
|
|
@@ -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()); | ||
|
|
@@ -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} | ||
| */ | ||
| skipAnimations_() { | ||
| return ( | ||
| prefersReducedMotion(this.ampdoc_.win) || | ||
| (isExperimentOn( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)) | ||
| ); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This still disables animations on non transformed documents |
||
| } | ||
|
|
||
| /** Bus for animation sequencing. */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@private