diff --git a/extensions/amp-story/1.0/amp-story-system-layer.js b/extensions/amp-story/1.0/amp-story-system-layer.js index 1a1c461faba5..5df54df9bdb5 100644 --- a/extensions/amp-story/1.0/amp-story-system-layer.js +++ b/extensions/amp-story/1.0/amp-story-system-layer.js @@ -92,105 +92,115 @@ const HIDE_MESSAGE_TIMEOUT_MS = 1500; /** * @param {!Element} element * @param {?Element=} children + * @param {boolean} isVisible * @return {!Element} */ -const renderSystemLayerElement = (element, children) => ( - + ); + + if (!isVisible) { + systemLayerElement.classList.add('i-amphtml-story-hidden'); + } + + return systemLayerElement; +}; /** * Contains the event name belonging to the viewer control. @@ -282,17 +292,19 @@ export class SystemLayer { } /** - * @return {!Element} * @param {string} initialPageId + * @param {boolean=} isVisible + * @return {!Element} */ - build(initialPageId) { + build(initialPageId, isVisible = true) { if (this.root_) { return this.root_; } this.systemLayerEl_ = renderSystemLayerElement( this.parentEl_, - this.progressBar_.build(initialPageId) + this.progressBar_.build(initialPageId), + isVisible ); localizeTemplate(this.systemLayerEl_, this.parentEl_); diff --git a/extensions/amp-story/1.0/amp-story.js b/extensions/amp-story/1.0/amp-story.js index 9af8731a6b7e..b3a845917e8e 100644 --- a/extensions/amp-story/1.0/amp-story.js +++ b/extensions/amp-story/1.0/amp-story.js @@ -583,12 +583,13 @@ export class AmpStory extends AMP.BaseElement { /** * Builds the system layer DOM. * @param {string} initialPageId + * @param {boolean} isVisible * @private */ - buildSystemLayer_(initialPageId) { + buildSystemLayer_(initialPageId, isVisible) { this.updateAudioIcon_(); this.updatePausedIcon_(); - this.element.appendChild(this.systemLayer_.build(initialPageId)); + this.element.appendChild(this.systemLayer_.build(initialPageId, isVisible)); } /** @private */ @@ -949,7 +950,16 @@ export class AmpStory extends AMP.BaseElement { layoutStory_() { const initialPageId = this.getInitialPageId_(); - this.buildSystemLayer_(initialPageId); + const shouldShowSystemLayer = !this.getAmpDoc().isPreview(); + if (!shouldShowSystemLayer) { + // The default value of `SYSTEM_UI_IS_VISIBLE_STATE` is `true`. We set it + // to `false` here solely to ensure that a subsequent firing of the + // `TOGGLE_SYSTEM_UI_IS_VISIBLE` action with a `true` value registers as + // a change in state instead of being a no-op. + this.storeService_.dispatch(Action.TOGGLE_SYSTEM_UI_IS_VISIBLE, false); + } + this.buildSystemLayer_(initialPageId, shouldShowSystemLayer); + this.setThemeColor_(); const storyLayoutPromise = Promise.all([ @@ -1699,6 +1709,14 @@ export class AmpStory extends AMP.BaseElement { const vState = this.getAmpDoc().getVisibilityState(); const isPreview = vState === VisibilityState_Enum.PREVIEW; const isVisible = vState === VisibilityState_Enum.VISIBLE; + + if (isPreview) { + this.storeService_.dispatch(Action.TOGGLE_SYSTEM_UI_IS_VISIBLE, false); + } + if (isVisible) { + this.storeService_.dispatch(Action.TOGGLE_SYSTEM_UI_IS_VISIBLE, true); + } + isPreview || isVisible ? this.resume_() : this.pause_(); } diff --git a/src/service/ampdoc-impl.js b/src/service/ampdoc-impl.js index 459bb2c1795e..ca176a0b4d29 100644 --- a/src/service/ampdoc-impl.js +++ b/src/service/ampdoc-impl.js @@ -727,6 +727,14 @@ export class AmpDoc { return devAssert(this.visibilityState_); } + /** + * Whether the AMP document currently being previewed. + * @return {boolean} + */ + isPreview() { + return this.visibilityState_ == VisibilityState_Enum.PREVIEW; + } + /** * Whether the AMP document currently visible. The reasons why it might not * be visible include user switching to another tab, browser running the