Skip to content

Commit 457b404

Browse files
✨ [Amp story player] [panel player] Launch panel player (#35423)
* Remove desktop from variables. Remove experiment flag. * Update z-index * Update tests and lint. * lint * Update tests. * Update z-index * Revert z-index
1 parent 780b55d commit 457b404

6 files changed

Lines changed: 64 additions & 79 deletions

File tree

css/Z_INDEX.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@
102102
| `amp-story-grid-layer` | 2 | [extensions/amp-story/1.0/amp-story.css](/extensions/amp-story/1.0/amp-story.css) |
103103
| `.controls` | 1 | [css/amp-ima-video-iframe.css](/css/amp-ima-video-iframe.css) |
104104
| `.amp-story-player-exit-control-button` | 1 | [css/amp-story-player-shadow.css](/css/amp-story-player-shadow.css) |
105-
| `.i-amphtml-story-player-desktop-panel-next` | 1 | [css/amp-story-player-shadow.css](/css/amp-story-player-shadow.css) |
106-
| `.i-amphtml-story-player-desktop-panel-prev` | 1 | [css/amp-story-player-shadow.css](/css/amp-story-player-shadow.css) |
105+
| `.i-amphtml-story-player-panel-next` | 1 | [css/amp-story-player-shadow.css](/css/amp-story-player-shadow.css) |
106+
| `.i-amphtml-story-player-panel-prev` | 1 | [css/amp-story-player-shadow.css](/css/amp-story-player-shadow.css) |
107107
| `.i-amphtml-layout-size-defined > [fallback]` | 1 | [css/ampshared.css](/css/ampshared.css) |
108108
| `.i-amphtml-layout-size-defined > [placeholder]` | 1 | [css/ampshared.css](/css/ampshared.css) |
109109
| `.i-amphtml-loading-container` | 1 | [css/ampshared.css](/css/ampshared.css) |

css/amp-story-player-shadow.css

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -78,35 +78,35 @@
7878
display: none;
7979
}
8080

81-
/* For desktop panel player UI. */
81+
/* For panel player UI. */
8282

8383
/**
8484
* NOTE: If you change any variables or media queries change:
8585
* extensions/amp-story/1.0/amp-story-desktop-one-panel.css
8686
*/
8787

88-
.i-amphtml-story-player-desktop-panel {
89-
--i-amphtml-story-player-desktop-panel-ratio: 69 / 116;
90-
--i-amphtml-story-player-desktop-panel-responsive-margin: max(74px, calc(var(--i-amphtml-story-player-height) * .0825));
88+
.i-amphtml-story-player-panel {
89+
--i-amphtml-story-player-panel-ratio: 69 / 116;
90+
--i-amphtml-story-player-panel-responsive-margin: max(74px, calc(var(--i-amphtml-story-player-height) * .0825));
9191
/** Calculates panel height by subtracting responsive vertical margin. */
92-
--i-amphtml-story-player-desktop-panel-height: calc(var(--i-amphtml-story-player-height) - var(--i-amphtml-story-player-desktop-panel-responsive-margin) * 2);
93-
--i-amphtml-story-player-desktop-panel-width: calc(var(--i-amphtml-story-player-desktop-panel-height) * var(--i-amphtml-story-player-desktop-panel-ratio));
94-
--i-amphtml-story-player-desktop-panel-button-margin: max(10px, calc(50vw - 145px - var(--i-amphtml-story-player-desktop-panel-width) / 2));
92+
--i-amphtml-story-player-panel-height: calc(var(--i-amphtml-story-player-height) - var(--i-amphtml-story-player-panel-responsive-margin) * 2);
93+
--i-amphtml-story-player-panel-width: calc(var(--i-amphtml-story-player-panel-height) * var(--i-amphtml-story-player-panel-ratio));
94+
--i-amphtml-story-player-panel-button-margin: max(10px, calc(50vw - 145px - var(--i-amphtml-story-player-panel-width) / 2));
9595
}
9696

9797
/* Override if iframe height is less than 756px. */
98-
.i-amphtml-story-player-desktop-panel.i-amphtml-story-player-desktop-panel-medium {
99-
--i-amphtml-story-player-desktop-panel-responsive-margin: 0px;
100-
--i-amphtml-story-player-desktop-panel-width: calc(var(--i-amphtml-story-player-height) * var(--i-amphtml-story-player-desktop-panel-ratio));
98+
.i-amphtml-story-player-panel.i-amphtml-story-player-panel-medium {
99+
--i-amphtml-story-player-panel-responsive-margin: 0px;
100+
--i-amphtml-story-player-panel-width: calc(var(--i-amphtml-story-player-height) * var(--i-amphtml-story-player-panel-ratio));
101101
}
102102

103103
/* Override if iframe height is less than 538px. */
104-
.i-amphtml-story-player-desktop-panel.i-amphtml-story-player-desktop-panel-small {
105-
--i-amphtml-story-player-desktop-panel-ratio: 3 / 4;
104+
.i-amphtml-story-player-panel.i-amphtml-story-player-panel-small {
105+
--i-amphtml-story-player-panel-ratio: 3 / 4;
106106
}
107107

108-
.i-amphtml-story-player-desktop-panel-prev,
109-
.i-amphtml-story-player-desktop-panel-next {
108+
.i-amphtml-story-player-panel-prev,
109+
.i-amphtml-story-player-panel-next {
110110
position: absolute;
111111
top: 50%;
112112
transform: translateY(-50%);
@@ -121,34 +121,36 @@
121121
transition: 150ms opacity;
122122
}
123123

124-
.i-amphtml-story-player-desktop-panel-prev[disabled],
125-
.i-amphtml-story-player-desktop-panel-next[disabled] {
124+
.i-amphtml-story-player-panel-prev[disabled],
125+
.i-amphtml-story-player-panel-next[disabled] {
126126
opacity: .1;
127127
cursor: initial;
128128
}
129129

130-
.i-amphtml-story-player-full-bleed-story .i-amphtml-story-player-desktop-panel-prev,
131-
.i-amphtml-story-player-full-bleed-story .i-amphtml-story-player-desktop-panel-next {
130+
.i-amphtml-story-player-full-bleed-story .i-amphtml-story-player-panel-prev,
131+
.i-amphtml-story-player-full-bleed-story .i-amphtml-story-player-panel-next,
132+
:not(.i-amphtml-story-player-panel) .i-amphtml-story-player-panel-prev,
133+
:not(.i-amphtml-story-player-panel) .i-amphtml-story-player-panel-next {
132134
opacity: 0;
133135
pointer-events: none;
134136
}
135137

136-
.i-amphtml-story-player-desktop-panel-prev {
137-
margin-inline-start: calc(var(--i-amphtml-story-player-desktop-panel-button-margin));
138+
.i-amphtml-story-player-panel-prev {
139+
margin-inline-start: calc(var(--i-amphtml-story-player-panel-button-margin));
138140
background-image: url('data:image/svg+xml;charset=utf-8,<svg width="16" height="16" viewBox="0 0 16 16" fill="white" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M4.66667 8L16 16V0L4.66667 8ZM0 16H2.66667V0H0V16Z"/><path fill-rule="evenodd" clip-rule="evenodd" d="M4.66667 8L16 16V0L4.66667 8ZM0 16H2.66667V0H0V16Z"/></svg>')!important;
139141
}
140142

141-
.i-amphtml-story-player-desktop-panel-next {
142-
margin-inline-end: var(--i-amphtml-story-player-desktop-panel-button-margin);
143+
.i-amphtml-story-player-panel-next {
144+
margin-inline-end: var(--i-amphtml-story-player-panel-button-margin);
143145
background-image: url('data:image/svg+xml;charset=utf-8,<svg width="16" height="16" viewBox="0 0 16 16" fill="white" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M11.3333 8L0 16V0L11.3333 8ZM16 16H13.3333V0H16V16Z"/><path fill-rule="evenodd" clip-rule="evenodd" d="M11.3333 8L0 16V0L11.3333 8ZM16 16H13.3333V0H16V16Z"/></svg>')!important;
144146
right: 0;
145147
}
146148

147-
[dir="rtl"].i-amphtml-story-player-desktop-panel-prev {
149+
[dir="rtl"].i-amphtml-story-player-panel-prev {
148150
right: 0;
149151
}
150152

151-
[dir="rtl"].i-amphtml-story-player-desktop-panel-next {
153+
[dir="rtl"].i-amphtml-story-player-panel-next {
152154
background-image: url('data:image/svg+xml;charset=utf-8,<svg width="16" height="16" viewBox="0 0 16 16" fill="white" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M4.66667 8L16 16V0L4.66667 8ZM0 16H2.66667V0H0V16Z"/><path fill-rule="evenodd" clip-rule="evenodd" d="M4.66667 8L16 16V0L4.66667 8ZM0 16H2.66667V0H0V16Z"/></svg>')!important;
153155
left: 0;
154156
}

extensions/amp-story-player/0.1/test/test-e2e/test-amp-story-player-prerender.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ describes.endtoend(
5151
'childElementCount'
5252
);
5353

54-
await expect(count).to.eql(0);
54+
// 2 accounts for previous and next buttons in panel player.
55+
await expect(count).to.eql(2);
5556
});
5657

5758
it('when player becomes visible in viewport, first story starts playing', async () => {

src/amp-story-player/amp-story-player-impl.js

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ const LOG_TYPE = {
176176
* NOTE: If udpated here, update in amp-story.js
177177
* @private @const {number}
178178
*/
179-
const DESKTOP_ONE_PANEL_ASPECT_RATIO_THRESHOLD = 3 / 4;
179+
const PANEL_ASPECT_RATIO_THRESHOLD = 3 / 4;
180180

181181
/**
182182
* Note that this is a vanilla JavaScript class and should not depend on AMP
@@ -252,14 +252,6 @@ export class AmpStoryPlayer {
252252
/** @private {?Element} */
253253
this.nextButton_ = null;
254254

255-
/**
256-
* Shows or hides the desktop panels player experiment.
257-
* Variable is set on window for unit testing new features.
258-
* @private {?boolean}
259-
*/
260-
this.isDesktopPanelExperimentOn_ =
261-
this.win_.DESKTOP_PANEL_STORY_PLAYER_EXP_ON;
262-
263255
return this.element_;
264256
}
265257

@@ -408,9 +400,7 @@ export class AmpStoryPlayer {
408400
this.initializeAttribution_();
409401
this.initializePageScroll_();
410402
this.initializeCircularWrapping_();
411-
if (this.isDesktopPanelExperimentOn_) {
412-
this.initializeDesktopStoryControlUI_();
413-
}
403+
this.initializeDesktopStoryControlUI_();
414404
this.signalReady_();
415405
this.element_.isBuilt_ = true;
416406
}
@@ -732,36 +722,36 @@ export class AmpStoryPlayer {
732722
new AmpStoryPlayerViewportObserver(this.win_, this.element_, () =>
733723
this.visibleDeferred_.resolve()
734724
);
735-
if (this.isDesktopPanelExperimentOn_) {
736-
if (this.win_.ResizeObserver) {
737-
new this.win_.ResizeObserver((e) => {
738-
const {height, width} = e[0].contentRect;
739-
this.onPlayerResize_(height, width);
740-
}).observe(this.element_);
741-
} else {
742-
// Set size once as fallback for browsers not supporting ResizeObserver.
743-
const {height, width} = this.element_./*OK*/ getBoundingClientRect();
725+
726+
if (this.win_.ResizeObserver) {
727+
new this.win_.ResizeObserver((e) => {
728+
const {height, width} = e[0].contentRect;
744729
this.onPlayerResize_(height, width);
745-
}
730+
}).observe(this.element_);
731+
} else {
732+
// Set size once as fallback for browsers not supporting ResizeObserver.
733+
const {height, width} = this.element_./*OK*/ getBoundingClientRect();
734+
this.onPlayerResize_(height, width);
746735
}
736+
747737
this.render_();
748738

749739
this.element_.isLaidOut_ = true;
750740
}
751741

752742
/**
753-
* Builds desktop "previous" and "next" story UI.
743+
* Builds panel mode "previous" and "next" story UI.
754744
* @private
755745
*/
756746
initializeDesktopStoryControlUI_() {
757747
this.prevButton_ = this.doc_.createElement('button');
758-
this.prevButton_.classList.add('i-amphtml-story-player-desktop-panel-prev');
748+
this.prevButton_.classList.add('i-amphtml-story-player-panel-prev');
759749
this.prevButton_.addEventListener('click', () => this.previous_());
760750
this.prevButton_.setAttribute('aria-label', 'previous story');
761751
this.rootEl_.appendChild(this.prevButton_);
762752

763753
this.nextButton_ = this.doc_.createElement('button');
764-
this.nextButton_.classList.add('i-amphtml-story-player-desktop-panel-next');
754+
this.nextButton_.classList.add('i-amphtml-story-player-panel-next');
765755
this.nextButton_.addEventListener('click', () => this.next_());
766756
this.nextButton_.setAttribute('aria-label', 'next story');
767757
this.rootEl_.appendChild(this.nextButton_);
@@ -770,7 +760,7 @@ export class AmpStoryPlayer {
770760
}
771761

772762
/**
773-
* Toggles disabled attribute on desktop "previous" and "next" buttons.
763+
* Toggles disabled attribute on panel mode "previous" and "next" buttons.
774764
* @private
775765
*/
776766
checkButtonsDisabled_() {
@@ -792,26 +782,22 @@ export class AmpStoryPlayer {
792782
* @private
793783
*/
794784
onPlayerResize_(height, width) {
795-
const isDesktopOnePanel =
796-
width / height > DESKTOP_ONE_PANEL_ASPECT_RATIO_THRESHOLD;
785+
const isPanel = width / height > PANEL_ASPECT_RATIO_THRESHOLD;
797786

798-
this.rootEl_.classList.toggle(
799-
'i-amphtml-story-player-desktop-panel',
800-
isDesktopOnePanel
801-
);
787+
this.rootEl_.classList.toggle('i-amphtml-story-player-panel', isPanel);
802788

803-
if (isDesktopOnePanel) {
789+
if (isPanel) {
804790
setStyles(this.rootEl_, {
805791
'--i-amphtml-story-player-height': `${height}px`,
806792
});
807793

808794
this.rootEl_.classList.toggle(
809-
'i-amphtml-story-player-desktop-panel-medium',
795+
'i-amphtml-story-player-panel-medium',
810796
height < 756
811797
);
812798

813799
this.rootEl_.classList.toggle(
814-
'i-amphtml-story-player-desktop-panel-small',
800+
'i-amphtml-story-player-panel-small',
815801
height < 538
816802
);
817803
}
@@ -950,12 +936,11 @@ export class AmpStoryPlayer {
950936
'remaining': remaining,
951937
};
952938

953-
if (this.isDesktopPanelExperimentOn_) {
954-
this.checkButtonsDisabled_();
955-
this.getUiState_().then((uiTypeNumber) =>
956-
this.onUiStateUpdate_(uiTypeNumber)
957-
);
958-
}
939+
this.checkButtonsDisabled_();
940+
this.getUiState_().then((uiTypeNumber) =>
941+
this.onUiStateUpdate_(uiTypeNumber)
942+
);
943+
959944
this.signalNavigation_(navigation);
960945
this.maybeFetchMoreStories_(remaining);
961946
}
@@ -1548,10 +1533,8 @@ export class AmpStoryPlayer {
15481533
this.onMutedStateUpdate_(/** @type {string} */ (data.value));
15491534
break;
15501535
case STORY_MESSAGE_STATE_TYPE.UI_STATE:
1551-
if (this.isDesktopPanelExperimentOn_) {
1552-
// Handles UI state updates on window resize.
1553-
this.onUiStateUpdate_(/** @type {number} */ (data.value));
1554-
}
1536+
// Handles UI state updates on window resize.
1537+
this.onUiStateUpdate_(/** @type {number} */ (data.value));
15551538
break;
15561539
case AMP_STORY_PLAYER_EVENT:
15571540
this.onPlayerEvent_(/** @type {string} */ (data.value));

test/e2e/test-amp-story-player-prerender.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ describes.endtoend(
5151
'childElementCount'
5252
);
5353

54-
await expect(count).to.eql(0);
54+
// 2 accounts for previous and next buttons in panel player.
55+
await expect(count).to.eql(2);
5556
});
5657

5758
it('when player is not visible in first viewport and on first user scroll, iframe loads first story in prerender', async () => {

test/unit/test-amp-story-player.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,12 +1506,10 @@ describes.realWin('AmpStoryPlayer', {amp: false}, (env) => {
15061506

15071507
await player.load();
15081508

1509-
expect(
1510-
playerEl.querySelector('.i-amphtml-story-player-desktop-panel-prev')
1511-
).to.exist;
1512-
expect(
1513-
playerEl.querySelector('.i-amphtml-story-player-desktop-panel-next')
1514-
).to.exist;
1509+
expect(playerEl.querySelector('.i-amphtml-story-player-panel-prev')).to
1510+
.exist;
1511+
expect(playerEl.querySelector('.i-amphtml-story-player-panel-next')).to
1512+
.exist;
15151513
});
15161514

15171515
it('Should get UI state on resize', async () => {

0 commit comments

Comments
 (0)