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

✨ Add an attribute to amp-story in order to hide share story button #40243

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion examples/amp-story/amp-story-social-share.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
</head>

<body>
<amp-story standalone>
<amp-story standalone hide-share-button>
<amp-story-page id="fill-template-title">
<amp-social-share class="rounded flex whatsapp i-amphtml-built i-amphtml-layout i-amphtml-element"
aria-label="Share" type="whatsapp" i-amphtml-layout="fixed" role="button" tabindex="0">Share on
Expand Down
6 changes: 6 additions & 0 deletions extensions/amp-story/1.0/amp-story-store-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@
TOGGLE_PAGE_HAS_ELEMENT_WITH_PLAYBACK: 'togglePageHasElementWithPlayblack',
TOGGLE_PAUSED: 'togglePaused',
TOGGLE_RTL: 'toggleRtl',
TOGGLE_SHARE_BUTTON: 'toggleShareButton',
TOGGLE_SHARE_MENU: 'toggleShareMenu',
TOGGLE_STORY_HAS_BACKGROUND_AUDIO: 'toggleStoryHasBackgroundAudio',
TOGGLE_STORY_HAS_PLAYBACK_UI: 'toggleStoryHasPlaybackUi',
Expand Down Expand Up @@ -420,6 +421,11 @@
...state,
[StateProperty.KEYBOARD_ACTIVE_STATE]: !!data,
});
case Action.TOGGLE_SHARE_BUTTON:
return /** @type {!State} */ ({

Check warning on line 425 in extensions/amp-story/1.0/amp-story-store-service.js

View check run for this annotation

Codecov / codecov/patch

extensions/amp-story/1.0/amp-story-store-service.js#L425

Added line #L425 was not covered by tests
...state,
[StateProperty.CAN_SHOW_SHARING_UIS]: !!data,
});
case Action.TOGGLE_SHARE_MENU:
return /** @type {!State} */ ({
...state,
Expand Down
24 changes: 24 additions & 0 deletions extensions/amp-story/1.0/amp-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
ADVANCE_TO: 'i-amphtml-advance-to',
AUTO_ADVANCE_AFTER: 'auto-advance-after',
AUTO_ADVANCE_TO: 'auto-advance-to',
NO_SHARING: 'hide-share-button',
MUTED: 'muted',
ORIENTATION: 'orientation',
PUBLIC_ADVANCE_TO: 'advance-to',
Expand Down Expand Up @@ -373,6 +374,10 @@
this.initializeStandaloneStory_();
}

if (this.isShareButtonHidden_()) {
this.initializeShareButton_(false);

Check warning on line 378 in extensions/amp-story/1.0/amp-story.js

View check run for this annotation

Codecov / codecov/patch

extensions/amp-story/1.0/amp-story.js#L378

Added line #L378 was not covered by tests
}

// buildCallback already runs in a mutate context. Calling another
// mutateElement explicitly will force the runtime to remeasure the
// amp-story element, fixing rendering bugs where the story is inactive
Expand Down Expand Up @@ -576,6 +581,16 @@
this.onResizeDebounced();
}

/**
* Initializes the share button by toggling its visibility.
*
* @param {boolean} canShow - A boolean indicating whether the share button should be shown.
* @private
*/
initializeShareButton_(canShow) {
this.storeService_.dispatch(Action.TOGGLE_SHARE_BUTTON, canShow);

Check warning on line 591 in extensions/amp-story/1.0/amp-story.js

View check run for this annotation

Codecov / codecov/patch

extensions/amp-story/1.0/amp-story.js#L591

Added line #L591 was not covered by tests
}

/**
* Initializes page ids by deduplicating them.
* @private
Expand Down Expand Up @@ -2022,6 +2037,15 @@
return this.element.hasAttribute(Attributes.SUPPORTS_LANDSCAPE);
}

/**
* Checks if the share button is hidden.
* @return {boolean} True if the share button is hidden, false otherwise.
* @private
*/
isShareButtonHidden_() {
return this.element.hasAttribute(Attributes.NO_SHARING);
}

/**
* Reacts to paused state updates.
* @param {boolean} isPaused
Expand Down
9 changes: 9 additions & 0 deletions extensions/amp-story/1.0/test/test-amp-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,15 @@ describes.realWin(
]);
});

it('should hide the share button', async () => {
await createStoryWithPages(2, ['cover', 'page-1']);
story.element.setAttribute('hide-share-button', '');
story.buildCallback();
await story.layoutCallback();
expect(story.storeService_.get(StateProperty.CAN_SHOW_SHARING_UIS)).to.be
.false;
});

describe('amp-story consent', () => {
it('should pause the story if there is a consent', async () => {
await createStoryWithPages(2, ['cover', 'page-1']);
Expand Down
Loading