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 Preview] Hide the system layer and progress bar in preview mode #38163

Merged
merged 15 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from 10 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
172 changes: 92 additions & 80 deletions extensions/amp-story/1.0/amp-story-system-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,105 +92,115 @@ const HIDE_MESSAGE_TIMEOUT_MS = 1500;
/**
* @param {!Element} element
* @param {?Element=} children
* @param {boolean} isHidden
* @return {!Element}
*/
const renderSystemLayerElement = (element, children) => (
<aside class="i-amphtml-story-system-layer i-amphtml-story-system-reset">
{children}
<a class={String(ATTRIBUTION_CLASS)} target="_blank">
<div class="i-amphtml-story-attribution-logo-container">
<img alt="" class="i-amphtml-story-attribution-logo" />
const renderSystemLayerElement = (element, children, isHidden) => {
coreymasanto marked this conversation as resolved.
Show resolved Hide resolved
const systemLayerElement = (
<aside class="i-amphtml-story-system-layer i-amphtml-story-system-reset">
{children}
<a class={String(ATTRIBUTION_CLASS)} target="_blank">
<div class="i-amphtml-story-attribution-logo-container">
<img alt="" class="i-amphtml-story-attribution-logo" />
</div>
<div class="i-amphtml-story-attribution-text" />
</a>
<div class="i-amphtml-story-has-new-page-notification-container">
<div class="i-amphtml-story-has-new-page-text-wrapper">
<span class="i-amphtml-story-has-new-page-circle-icon" />
<div
class="i-amphtml-story-has-new-page-text"
i-amphtml-i18n-text-content={
LocalizedStringId_Enum.AMP_STORY_HAS_NEW_PAGE_TEXT
}
></div>
</div>
</div>
<div class="i-amphtml-story-attribution-text" />
</a>
<div class="i-amphtml-story-has-new-page-notification-container">
<div class="i-amphtml-story-has-new-page-text-wrapper">
<span class="i-amphtml-story-has-new-page-circle-icon" />
<div class="i-amphtml-story-system-layer-buttons">
<div
class="i-amphtml-story-has-new-page-text"
i-amphtml-i18n-text-content={
LocalizedStringId_Enum.AMP_STORY_HAS_NEW_PAGE_TEXT
}
></div>
</div>
</div>
<div class="i-amphtml-story-system-layer-buttons">
<div
role="button"
class={INFO_CLASS + ' i-amphtml-story-button'}
i-amphtml-i18n-aria-label={
LocalizedStringId_Enum.AMP_STORY_INFO_BUTTON_LABEL
}
/>
<div class="i-amphtml-story-captions-display">
<button
class={CAPTIONS_CLASS + ' i-amphtml-story-button'}
role="button"
class={INFO_CLASS + ' i-amphtml-story-button'}
i-amphtml-i18n-aria-label={
LocalizedStringId_Enum.AMP_STORY_CAPTIONS_ON_LABEL
LocalizedStringId_Enum.AMP_STORY_INFO_BUTTON_LABEL
}
/>
<div class="i-amphtml-story-captions-display">
<button
class={CAPTIONS_CLASS + ' i-amphtml-story-button'}
i-amphtml-i18n-aria-label={
LocalizedStringId_Enum.AMP_STORY_CAPTIONS_ON_LABEL
}
/>
<button
class={NOCAPTIONS_CLASS + ' i-amphtml-story-button'}
i-amphtml-i18n-aria-label={
LocalizedStringId_Enum.AMP_STORY_CAPTIONS_OFF_LABEL
}
/>
</div>
<div class="i-amphtml-story-sound-display">
<button
class={UNMUTE_CLASS + ' i-amphtml-story-button'}
i-amphtml-i18n-aria-label={
LocalizedStringId_Enum.AMP_STORY_AUDIO_UNMUTE_BUTTON_LABEL
}
/>
<button
class={MUTE_CLASS + ' i-amphtml-story-button'}
i-amphtml-i18n-aria-label={
LocalizedStringId_Enum.AMP_STORY_AUDIO_MUTE_BUTTON_LABEL
}
/>
</div>
<div class="i-amphtml-paused-display">
<button
class={PAUSE_CLASS + ' i-amphtml-story-button'}
i-amphtml-i18n-aria-label={
LocalizedStringId_Enum.AMP_STORY_PAUSE_BUTTON_LABEL
}
/>
<button
class={PLAY_CLASS + ' i-amphtml-story-button'}
i-amphtml-i18n-aria-label={
LocalizedStringId_Enum.AMP_STORY_PLAY_BUTTON_LABEL
}
/>
</div>
<button
class={NOCAPTIONS_CLASS + ' i-amphtml-story-button'}
i-amphtml-i18n-aria-label={
LocalizedStringId_Enum.AMP_STORY_CAPTIONS_OFF_LABEL
class={
SKIP_TO_NEXT_CLASS +
' i-amphtml-story-ui-hide-button i-amphtml-story-button'
}
/>
</div>
<div class="i-amphtml-story-sound-display">
<button
class={UNMUTE_CLASS + ' i-amphtml-story-button'}
i-amphtml-i18n-aria-label={
LocalizedStringId_Enum.AMP_STORY_AUDIO_UNMUTE_BUTTON_LABEL
LocalizedStringId_Enum.AMP_STORY_SKIP_TO_NEXT_BUTTON_LABEL
}
/>
<button
class={MUTE_CLASS + ' i-amphtml-story-button'}
class={SHARE_CLASS + ' i-amphtml-story-button'}
i-amphtml-i18n-aria-label={
LocalizedStringId_Enum.AMP_STORY_AUDIO_MUTE_BUTTON_LABEL
LocalizedStringId_Enum.AMP_STORY_SHARE_BUTTON_LABEL
}
/>
</div>
<div class="i-amphtml-paused-display">
<button
class={PAUSE_CLASS + ' i-amphtml-story-button'}
i-amphtml-i18n-aria-label={
LocalizedStringId_Enum.AMP_STORY_PAUSE_BUTTON_LABEL
class={
CLOSE_CLASS +
' i-amphtml-story-ui-hide-button i-amphtml-story-button'
}
/>
<button
class={PLAY_CLASS + ' i-amphtml-story-button'}
i-amphtml-i18n-aria-label={
LocalizedStringId_Enum.AMP_STORY_PLAY_BUTTON_LABEL
LocalizedStringId_Enum.AMP_STORY_CLOSE_BUTTON_LABEL
}
/>
</div>
<button
class={
SKIP_TO_NEXT_CLASS +
' i-amphtml-story-ui-hide-button i-amphtml-story-button'
}
i-amphtml-i18n-aria-label={
LocalizedStringId_Enum.AMP_STORY_SKIP_TO_NEXT_BUTTON_LABEL
}
/>
<button
class={SHARE_CLASS + ' i-amphtml-story-button'}
i-amphtml-i18n-aria-label={
LocalizedStringId_Enum.AMP_STORY_SHARE_BUTTON_LABEL
}
/>
<button
class={
CLOSE_CLASS + ' i-amphtml-story-ui-hide-button i-amphtml-story-button'
}
i-amphtml-i18n-aria-label={
LocalizedStringId_Enum.AMP_STORY_CLOSE_BUTTON_LABEL
}
/>
</div>
<div class="i-amphtml-story-system-layer-buttons-start-position" />
</aside>
);
<div class="i-amphtml-story-system-layer-buttons-start-position" />
</aside>
);

if (isHidden) {
systemLayerElement.classList.add('i-amphtml-story-hidden');
}

return systemLayerElement;
};

/**
* Contains the event name belonging to the viewer control.
Expand Down Expand Up @@ -282,17 +292,19 @@ export class SystemLayer {
}

/**
* @return {!Element}
* @param {string} initialPageId
* @param {boolean=} isHidden
* @return {!Element}
*/
build(initialPageId) {
build(initialPageId, isHidden = false) {
coreymasanto marked this conversation as resolved.
Show resolved Hide resolved
if (this.root_) {
return this.root_;
}

this.systemLayerEl_ = renderSystemLayerElement(
this.parentEl_,
this.progressBar_.build(initialPageId)
this.progressBar_.build(initialPageId),
isHidden
);
localizeTemplate(this.systemLayerEl_, this.parentEl_);

Expand Down
17 changes: 14 additions & 3 deletions extensions/amp-story/1.0/amp-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,12 +583,13 @@ export class AmpStory extends AMP.BaseElement {
/**
* Builds the system layer DOM.
* @param {string} initialPageId
* @param {boolean} isHidden
* @private
*/
buildSystemLayer_(initialPageId) {
buildSystemLayer_(initialPageId, isHidden) {
this.updateAudioIcon_();
this.updatePausedIcon_();
this.element.appendChild(this.systemLayer_.build(initialPageId));
this.element.appendChild(this.systemLayer_.build(initialPageId, isHidden));
}

/** @private */
Expand Down Expand Up @@ -949,7 +950,9 @@ export class AmpStory extends AMP.BaseElement {
layoutStory_() {
const initialPageId = this.getInitialPageId_();

this.buildSystemLayer_(initialPageId);
const shouldHideSystemLayer = this.getAmpDoc().isPreviewing();
coreymasanto marked this conversation as resolved.
Show resolved Hide resolved
this.buildSystemLayer_(initialPageId, shouldHideSystemLayer);

this.setThemeColor_();

const storyLayoutPromise = Promise.all([
Expand Down Expand Up @@ -1699,6 +1702,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) {
coreymasanto marked this conversation as resolved.
Show resolved Hide resolved
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_();
}

Expand Down
8 changes: 8 additions & 0 deletions src/service/ampdoc-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,14 @@ export class AmpDoc {
return devAssert(this.visibilityState_);
}

/**
* Whether the AMP document currently being previewed.
coreymasanto marked this conversation as resolved.
Show resolved Hide resolved
* @return {boolean}
*/
isPreviewing() {
coreymasanto marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down