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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰[story-ads] Pause the progress bar when paused. #34046

Merged
merged 2 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
animation: grow linear;
}

[paused] .i-amphtml-story-ad-progress-bar {
animation-play-state: paused;
}

@keyframes grow {
from {
width: 0%;
Expand Down
21 changes: 21 additions & 0 deletions extensions/amp-story-auto-ads/0.1/amp-story-auto-ads.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const Attributes = {
AD_SHOWING: 'ad-showing',
DESKTOP_PANELS: 'desktop-panels',
DIR: 'dir',
PAUSED: 'paused',
};

export class AmpStoryAutoAds extends AMP.BaseElement {
Expand Down Expand Up @@ -377,6 +378,26 @@ export class AmpStoryAutoAds extends AMP.BaseElement {
this.progressBarBackground_.appendChild(progressBar);
createShadowRootWithStyle(host, this.progressBarBackground_, progessBarCSS);
this.ampStory_.element.appendChild(host);

// TODO(#33969) move this to init listeners when no longer conditional.
this.storeService_.subscribe(StateProperty.PAUSED_STATE, (isPaused) => {
this.onPauseStateUpdate_(isPaused);
});
}

/**
* If video is paused and ad is showing pause the progress bar.
* @param {boolean} isPaused
*/
onPauseStateUpdate_(isPaused) {
const adShowing = this.storeService_.get(StateProperty.AD_STATE);
if (!adShowing) {
return;
}

isPaused
? this.progressBarBackground_.setAttribute(Attributes.PAUSED, '')
: this.progressBarBackground_.removeAttribute(Attributes.PAUSED);
}

/**
Expand Down
24 changes: 24 additions & 0 deletions extensions/amp-story-auto-ads/0.1/test/test-amp-story-auto-ads.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,30 @@ describes.realWin(
storeService.dispatch(Action.TOGGLE_RTL, true);
expect(adBadgeContainer).to.have.attribute(Attributes.DIR, 'rtl');
});

it('should propagate the pause state if ad showing', () => {
const progressBackground = doc.querySelector(
'.i-amphtml-story-ad-progress-background'
);
storeService.dispatch(Action.TOGGLE_AD, true);
expect(progressBackground).not.to.have.attribute(Attributes.PAUSED);
storeService.dispatch(Action.TOGGLE_PAUSED, true);
expect(progressBackground).to.have.attribute(Attributes.PAUSED);
storeService.dispatch(Action.TOGGLE_PAUSED, false);
expect(progressBackground).not.to.have.attribute(Attributes.PAUSED);
});

it('should not propagate the pause state if no ad showing', () => {
const progressBackground = doc.querySelector(
'.i-amphtml-story-ad-progress-background'
);
storeService.dispatch(Action.TOGGLE_AD, false);
expect(progressBackground).not.to.have.attribute(Attributes.PAUSED);
storeService.dispatch(Action.TOGGLE_PAUSED, true);
expect(progressBackground).not.to.have.attribute(Attributes.PAUSED);
storeService.dispatch(Action.TOGGLE_PAUSED, false);
expect(progressBackground).not.to.have.attribute(Attributes.PAUSED);
});
});

describe('analytics triggers', () => {
Expand Down