Skip to content

Commit

Permalink
⏪ [Story system layer] Audio icon disappears when story has backgroun…
Browse files Browse the repository at this point in the history
…d audio (#37314)

* Added tasts

* Undo

* Reverted changes and added test

* Removed newlines between test

* Removed extra bracket
  • Loading branch information
mszylkowski authored Jan 7, 2022
1 parent cbcf14a commit bfa2191
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
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 @@ -210,6 +210,7 @@ export const Action = {
TOGGLE_SHARE_MENU: 'toggleShareMenu',
ADD_SHOPPING_DATA: 'addShoppingData',
TOGGLE_STORY_HAS_PLAYBACK_UI: 'toggleStoryHasPlaybackUi',
TOGGLE_STORY_HAS_BACKGROUND_AUDIO: 'toggleStoryHasBackgroundAudio',
TOGGLE_SYSTEM_UI_IS_VISIBLE: 'toggleSystemUiIsVisible',
TOGGLE_UI: 'toggleUi',
SET_GYROSCOPE_PERMISSION: 'setGyroscopePermission',
Expand Down Expand Up @@ -340,6 +341,11 @@ const actions = (state, action, data) => {
...state,
[StateProperty.STORY_HAS_PLAYBACK_UI_STATE]: !!data,
});
case Action.TOGGLE_STORY_HAS_BACKGROUND_AUDIO:
return /** @type {!State} */ ({
...state,
[StateProperty.STORY_HAS_BACKGROUND_AUDIO_STATE]: !!data,
});
// Mutes or unmutes the story media.
case Action.TOGGLE_MUTED:
return /** @type {!State} */ ({
Expand Down
14 changes: 14 additions & 0 deletions extensions/amp-story/1.0/amp-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ export class AmpStory extends AMP.BaseElement {
* @private
*/
buildSystemLayer_(initialPageId) {
this.updateAudioIcon_();
this.updatePausedIcon_();
this.element.appendChild(this.systemLayer_.build(initialPageId));
}
Expand Down Expand Up @@ -2124,6 +2125,19 @@ export class AmpStory extends AMP.BaseElement {
this.mediaPool_.play(this.backgroundAudioEl_);
}

/**
* Update the store if the story has background audio.
* @private
*/
updateAudioIcon_() {
const storyHasBackgroundAudio =
this.element.hasAttribute('background-audio');
this.storeService_.dispatch(
Action.TOGGLE_STORY_HAS_BACKGROUND_AUDIO,
storyHasBackgroundAudio
);
}

/**
* Shows the play/pause icon if there is an element with playback on the story.
* @private
Expand Down
12 changes: 12 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 @@ -921,6 +921,18 @@ describes.realWin(
});
});

it('should update the STORY_HAS_BACKGROUND_AUDIO property if story has background audio', async () => {
await createStoryWithPages(2, ['cover', 'page-1']);
story.element.setAttribute('background-audio', 'audio.mp3');
await story.layoutCallback();

expect(
story.storeService_.get(
StateProperty.STORY_HAS_BACKGROUND_AUDIO_STATE
)
).to.be.true;
});

it('should remove the muted attribute on unmuted state change', async () => {
await createStoryWithPages(2, ['cover', 'page-1']);

Expand Down

1 comment on commit bfa2191

@gifhuppp
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[ชั้นระบบเรื่องราว] ไอคอนเสียงหายไปเมื่อเรื่องราวมีพื้นหลัง...

Please sign in to comment.