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

Defer building system layer until pages have been initialized #11878

Merged
merged 8 commits into from
Nov 1, 2017
14 changes: 11 additions & 3 deletions extensions/amp-story/0.1/amp-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,6 @@ export class AmpStory extends AMP.BaseElement {
this.lockBody_();
}

this.element.appendChild(
this.systemLayer_.build(this.getRealChildren().length));

this.initializeListeners_();
this.initializeListenersForDev_();

Expand All @@ -193,6 +190,16 @@ export class AmpStory extends AMP.BaseElement {
}


/**
* Builds the system layer DOM. This is dependent on the pages_ array having
* been initialized, so it cannot happen at build time.
* @private
*/
buildSystemLayer_() {
this.element.appendChild(this.systemLayer_.build(this.getPageCount()));
}


/** @private */
initializeListeners_() {
this.element.addEventListener(EventType.EXIT_FULLSCREEN, () => {
Expand Down Expand Up @@ -350,6 +357,7 @@ export class AmpStory extends AMP.BaseElement {
'Story must have at least one page.');

return this.initializePages_()
.then(() => this.buildSystemLayer_())
.then(() => {
this.pages_.forEach(page => {
page.setActive(false);
Expand Down