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

Dynamic page scaling in amp-story #12901

Merged
merged 16 commits into from Jan 30, 2018
Merged
14 changes: 12 additions & 2 deletions extensions/amp-story/0.1/amp-story-page.js
Expand Up @@ -32,8 +32,10 @@ import {upgradeBackgroundAudio} from './audio';
import {EventType, dispatch, dispatchCustom} from './events';
import {AdvancementConfig} from './page-advancement';
import {matches, scopedQuerySelectorAll} from '../../../src/dom';
import {dev} from '../../../src/log';
import {getLogEntries} from './logging';
import {getMode} from '../../../src/mode';
import {PageScalingService} from './page-scaling';
import {LoadingSpinner} from './loading-spinner';
import {listen} from '../../../src/event-helper';
import {debounce} from '../../../src/utils/rate-limit';
Expand Down Expand Up @@ -198,7 +200,7 @@ export class AmpStoryPage extends AMP.BaseElement {
/** @return {!Promise} */
beforeVisible() {
this.rewindAllMediaToBeginning_();
return this.maybeApplyFirstAnimationFrame();
return this.scale_().then(() => this.maybeApplyFirstAnimationFrame());
}


Expand Down Expand Up @@ -404,6 +406,14 @@ export class AmpStoryPage extends AMP.BaseElement {
return this.animationManager_.applyFirstFrame();
}

/**
* @return {!Promise}
* @private
*/
scale_() {
const storyEl = dev().assertElement(this.element.parentNode);
return PageScalingService.for(storyEl).scale(this.element);
}

/**
* @param {boolean} isActive
Expand Down Expand Up @@ -434,10 +444,10 @@ export class AmpStoryPage extends AMP.BaseElement {
*/
setDistance(distance) {
this.element.setAttribute('distance', distance);

this.registerAllMedia_();
if (distance > 0 && distance <= 2) {
this.preloadAllMedia_();
this.scale_();
}
}

Expand Down
6 changes: 6 additions & 0 deletions extensions/amp-story/0.1/amp-story.js
Expand Up @@ -250,6 +250,12 @@ export class AmpStory extends AMP.BaseElement {
buildCallback() {
this.assertAmpStoryExperiment_();

if (this.isDesktop_()) {
this.element.setAttribute('desktop','');
}

this.element.querySelector('amp-story-page').setAttribute('active', '');

if (this.element.hasAttribute(AMP_STORY_STANDALONE_ATTRIBUTE)) {
const html = this.win.document.documentElement;
this.mutateElement(() => {
Expand Down