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 supports-landscape attribute. #19849

Merged
merged 1 commit into from
Dec 14, 2018
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
44 changes: 10 additions & 34 deletions extensions/amp-story/1.0/amp-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const Attributes = {
DESKTOP_POSITION: 'i-amphtml-desktop-position',
VISITED: 'i-amphtml-visited', // stacked offscreen to left
AUTO_ADVANCE_AFTER: 'auto-advance-after',
SUPPORTED_ORIENTATIONS: 'supported-orientations',
SUPPORTS_LANDSCAPE: 'supports-landscape',
};

/**
Expand Down Expand Up @@ -187,12 +187,6 @@ const HIDE_ON_BOOKEND_SELECTOR =
*/
const DEFAULT_THEME_COLOR = '#F1F3F4';

/** @enum {string} */
const ScreenOrientations = {
PORTRAIT: 'portrait',
LANDSCAPE: 'landscape',
};

/**
* @implements {./media-pool.MediaPoolRoot}
*/
Expand Down Expand Up @@ -1298,9 +1292,9 @@ export class AmpStory extends AMP.BaseElement {
const uiState = this.getUIType_();
this.storeService_.dispatch(Action.TOGGLE_UI, uiState);

if (uiState !== UIType.MOBILE ||
this.getSupportedOrientations_()
.includes(ScreenOrientations.LANDSCAPE)) {
if (uiState !== UIType.MOBILE || this.isLandscapeSupported_()) {
// TODO: Rename the TOGGLE_LANDSCAPE action. (#19670)
// Hides the UI that prevents users from using the LANDSCAPE orientation.
this.storeService_.dispatch(Action.TOGGLE_LANDSCAPE, false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a comment / todo here please? It's still a bit confusing for me to read this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

return;
}
Expand Down Expand Up @@ -1397,9 +1391,7 @@ export class AmpStory extends AMP.BaseElement {
return UIType.MOBILE;
}

const supportedOrientations = this.getSupportedOrientations_();

if (supportedOrientations.includes(ScreenOrientations.LANDSCAPE)) {
if (this.isLandscapeSupported_()) {
return UIType.DESKTOP_FULLBLEED;
}

Expand All @@ -1425,29 +1417,13 @@ export class AmpStory extends AMP.BaseElement {
}

/**
* Returns an array of the supported orientations configured by the publisher.
* Defaults to ['portrait'].
* @return {!Array<string>}
* Whether the story should support landscape orientation: landscape mobile,
* or full bleed desktop UI.
* @return {boolean}
* @private
*/
getSupportedOrientations_() {
if (this.supportedOrientations_) {
return this.supportedOrientations_;
}

const supportedOrientationsAttribute =
this.element.getAttribute(Attributes.SUPPORTED_ORIENTATIONS);

if (!supportedOrientationsAttribute) {
return [ScreenOrientations.PORTRAIT];
}

this.supportedOrientations_ =
supportedOrientationsAttribute
.split(',')
.map(orientation => orientation.trim().toLowerCase());

return this.supportedOrientations_;
isLandscapeSupported_() {
return this.element.hasAttribute(Attributes.SUPPORTS_LANDSCAPE);
}

/**
Expand Down
19 changes: 17 additions & 2 deletions extensions/amp-story/1.0/test/test-amp-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,24 @@ describes.realWin('amp-story', {
});
});

it('should detect fullbleed desktop mode', () => {
it('should default to the three panels UI desktop experience', () => {
createPages(story.element, 4, ['cover', '1', '2', '3']);
story.element.setAttribute('supported-orientations', 'portrait, laNdsCApe');

// Don't do this at home. :(
story.desktopMedia_ = {matches: true};

story.buildCallback();

return story.layoutCallback()
.then(() => {
expect(story.storeService_.get(StateProperty.UI_STATE))
.to.equals(UIType.DESKTOP_PANELS);
});
});

it('should detect landscape opt in', () => {
createPages(story.element, 4, ['cover', '1', '2', '3']);
story.element.setAttribute('supports-landscape', '');

// Don't do this at home. :(
story.desktopMedia_ = {matches: true};
Expand Down