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 the core amp-story component #11511

Merged
merged 27 commits into from
Oct 4, 2017
Merged

Add the core amp-story component #11511

merged 27 commits into from
Oct 4, 2017

Conversation

newmuis
Copy link
Contributor

@newmuis newmuis commented Sep 29, 2017

Depends on a number of other PRs: #11502 #11484 #11485 #11506 #11487 #11509 #11510

html.i-amphtml-story-standalone body,
html[amp-story] body,
html[📖] body {
display: grid !important;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the body need be grid as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is display: grid for a different reason; this is our current "desktop UI," which is just a centered mobile-phone-sized screen. This will be removed soon, when we have a true desktop UI (that is being developed now).

max-width: 414px;
}

amp-story[standalone]:-webkit-full-screen,
Copy link
Contributor

Choose a reason for hiding this comment

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

Combine all fullscreen declarations below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fun fact: you can't :(

Some browsers find other browsers' vendor prefixes to be illegal selectors, and instead of dropping just that part of the compound selector, it drops the whole thing. In other words, because :-moz-full-screen is present in part of the selector, Chrome would drop amp-story[standalone]:-webkit-fullscreen, amp-story[standalone]:-moz-full-screen

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case, you should check what our CSS compiler does. I believe it combines all such selectors automatically.

animation-delay: 1.0s;
}

@keyframes grow {
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefix with i-amphtml-

}

.i-amphtml-story-bookend-article-meta {
font-family: 'Roboto', sans-serif;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this ok for a general support?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you mean the high level UX decision of using Roboto: amp-story has a pretty opinionated default UI as compared to other components.

If you mean whether the font will actually get loaded, we can consider adding an <amp-font> tag for it, internally to the component.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather actually somehow do font-display:optional thing for this. But it's ok.

Copy link
Contributor

Choose a reason for hiding this comment

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

But hows does Roboto gets included on pages? Forced by validator? Or we just fallback?

* @param {string} targetPageId
* @return {!Promise}
*/
// TODO: Update history state
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO(ldap)

@ampprojectbot ampprojectbot added this to the Pending Triage milestone Oct 2, 2017
@newmuis
Copy link
Contributor Author

newmuis commented Oct 3, 2017

Added /*OK*/ to usages of offsetLeft, offsetWidth, and offsetHeight in amp-story.js. PTAL

@newmuis newmuis requested a review from dreamofabear October 3, 2017 16:23
@newmuis
Copy link
Contributor Author

newmuis commented Oct 3, 2017

Adding @choumx, since he's on all of the other reviews.

This seems good to go as long as:

  1. The usages of offsetLeft offsetWidth and offsetHeight are okay (per my previous comment)
  2. The remaining dependency PRs Add audio support for amp-story #11509 Add amp-story-page element #11510 Implement bookend component for amp-story #11526 and Implement system layer components for amp-story #11527 get merged

Copy link

@dreamofabear dreamofabear left a comment

Choose a reason for hiding this comment

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

Minor comments. Use of offset* seems ok, though maybe I'm missing something.


/**
* @param {string} id The ID of the page to be retrieved.
* @return {!AmpStoryPage} Retrieves the page with the specified ID.

Choose a reason for hiding this comment

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

@private

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


/**
* @param {!Element} el
* @return {boolean}

Choose a reason for hiding this comment

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

@private

* @return {!AmpStoryPage} Retrieves the page with the specified ID.
*/
getPageById_(id) {
return user().assert(this.pages_.find(page => page.element.id === id),

Choose a reason for hiding this comment

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

Use array.js#findIndex. Array#find doesn't have IE support and I don't think we polyfill it.

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

.expandAsync(user().assertString(rawUrl))
.then(url => Services.xhrFor(this.win).fetchJson(url))
.then(response => {
user().assert(response.ok, 'Invalid HTTP response');

Choose a reason for hiding this comment

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

Nit: Add more error info for user debugging.

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 {!Promise<?./bookend.BookendConfig>}
*/

Choose a reason for hiding this comment

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

@private

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

.then(response => response && {
shareProviders: response['share-providers'],
relatedArticles: response['related-articles'] ?
buildFromJson(response['related-articles']) : [],

Choose a reason for hiding this comment

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

Minor: Can we change buildFromJson to just return [] on undefined input?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Filed #11549

* @param {string} pageId The page to be added to the map.
* @return {!Object<string, number>} A mapping from page ID to the priority of
* that page.
*/

Choose a reason for hiding this comment

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

@private

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

*/
getPagesByDistance_() {
const distanceMap = this.getPageDistanceMapHelper_(
/* distance */ 0, /* map */ {}, this.activePage_.element.id);

Choose a reason for hiding this comment

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

First argument is priority not distance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The variable name was the one that was wrong

const nextScreenAreaMin = this.element./*OK*/offsetLeft +
((1 - NEXT_SCREEN_AREA_RATIO) * this.element./*OK*/offsetWidth);
const nextScreenAreaMax = this.element./*OK*/offsetLeft +
this.element./*OK*/offsetWidth;

Choose a reason for hiding this comment

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

Nit: Hoist these into local vars for readability.

const offsetWidth = this.element./*OK*/offsetWidth;

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;
}

map = this.getPageDistanceMapHelper_(priority + 1, map, adjacentPageId);

Choose a reason for hiding this comment

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

Assignment to map (and I suppose the return value) doesn't seem necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Marked with a TODO

amp-story {
height: 100% !important;
Copy link
Contributor

Choose a reason for hiding this comment

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

let's force box-sizing: border-box; to ensure height and width 100% are still effective if authors decide to add padding/border

Choose a reason for hiding this comment

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

html.i-amphtml-story-standalone body,
html[amp-story] body,
html[📖] body {
height: 100% !important;
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto box-sizing

text-transform: uppercase;
font-size: 10px;
padding: 0 0 8px;
margin: 48px 0 8px;
Copy link
Contributor

Choose a reason for hiding this comment

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

this probably needs a RTL version to reverse the left/right numbers

}

.i-amphtml-story-share-list > li:first-child {
padding-left: 32px;
Copy link
Contributor

@aghassemi aghassemi Oct 3, 2017

Choose a reason for hiding this comment

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

ditto, this and below need rtl rules to reset left to 0 and apply 32px to right

@dreamofabear dreamofabear merged commit afd6ebd into ampproject:master Oct 4, 2017
@dreamofabear
Copy link

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants