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

amp-story initial load tweaks #12842

Merged
merged 33 commits into from Jan 19, 2018
Merged

amp-story initial load tweaks #12842

merged 33 commits into from Jan 19, 2018

Conversation

newmuis
Copy link
Contributor

@newmuis newmuis commented Jan 16, 2018

This fixes the initial styling of standalone amp-story elements by showing a blank white screen until the story is "loaded" (all the media assets on the initially-visible pages have loaded at least one frame).

/cc @ithinkihaveacat This PR adds an event (ampstory:load) that is triggered when the story is deemed loaded, as well as a CSS class (.i-amphtml-story-loaded) that gets added to the amp-story tag when it is loaded. You can also continue to use the page-level CSS class (.i-amphtml-story-page-loaded), and there is also an event (ampstory:pageload) that is triggered when a page is loaded.

/cc @hongwei1990 @christianbersch @flaviori

@newmuis newmuis changed the title Amp story initial load tweaks amp-story initial load tweaks Jan 16, 2018
@@ -1282,7 +1337,6 @@ export class AmpStory extends AMP.BaseElement {
if (this.bookend_.isActive()) {
// Dispaching event instead of calling method directly so that all
// listeners can respond.
dispatch(this.element, EventType.CLOSE_BOOKEND);
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you should remove 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.

How did that happen?!

Copy link
Member

Choose a reason for hiding this comment

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

My guess is cut/paste for dispatch? ;)

@@ -195,8 +202,15 @@ export class AmpStoryPage extends AMP.BaseElement {
}


/** @return {!Promise} */
waitUntilLoaded() {
Copy link
Member

Choose a reason for hiding this comment

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

nit: whenLoaded

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.


/** @private */
markStoryAsLoaded_() {
dispatch(this.element, EventType.STORY_LOADED, true);
Copy link
Member

Choose a reason for hiding this comment

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

Is there a listener for 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.

Not within the runtime; it's meant for embedding pages to listen to (e.g. test environments, tools, etc)

Copy link
Member

Choose a reason for hiding this comment

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

sg.

@@ -502,12 +520,49 @@ export class AmpStory extends AMP.BaseElement {
}


/** @private */
waitForInitialLoad_() {
Copy link
Member

Choose a reason for hiding this comment

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

Could be simpler. Can be one method. Timeout can be implied in parameter.

whenPagesLoaded_(pagesToWaitFor, timeoutMs = 0) {
  const pagesToWaitFor = this.isDesktop_() ?
      [this.pages_[0], this.pages_[1]] :
      [this.pages_[0]];

  const loadPromise = Promise.all(pagesToWaitFor.map(page => page.whenLoaded());

  return this.timer_.timeoutPromise(timeoutMs, loadPromise);
}

@@ -91,6 +91,19 @@ const DESKTOP_HEIGHT_THRESHOLD = 550;
/** @private @const {number} */
const MIN_SWIPE_FOR_HINT_OVERLAY_PX = 50;

/**
* The duration of time (in milliseconds) to wait for a page to be loaded.
Copy link
Member

Choose a reason for hiding this comment

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

...for a page to be loaded before story becomes visible.

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.

css/amp.css Outdated
@@ -803,6 +803,18 @@ amp-accordion > section[expanded] > :last-child {
width: 100%;
}

amp-story[standalone] {
background-color: #fff !important;
Copy link
Member

Choose a reason for hiding this comment

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

What if the author wants to override 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.

This is rarely ever shown. This is the background of the story itself, but not the pages, and all of our experiences show the background of the page (which the publisher can override). This should only show up while the story is loading.

Copy link
Member

Choose a reason for hiding this comment

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

Right, I missed that. Thanks.

@newmuis
Copy link
Contributor Author

newmuis commented Jan 16, 2018

@alanorozco PTAL when you get a chance

// promises to complete, even if one has failed. We do nothing with the
// error, as the resource itself and/or code that loads it should handle
// the error.
mediaEl.addEventListener('error', resolve, true /* useCapture */);
Copy link
Member

Choose a reason for hiding this comment

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

Does this change what gets output to the console in case of an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope 😄

/** @private */
markPageAsLoaded_() {
this.element.classList.add(PAGE_LOADED_CLASS_NAME);
this.mutateElement(() => {
dispatch(this.element, EventType.PAGE_LOADED, true);
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps dispatch event outside mutate callback.

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

@newmuis newmuis merged commit 27a032c into ampproject:master Jan 19, 2018
gzgogo pushed a commit to gzgogo/amphtml that referenced this pull request Jan 26, 2018
* Change progress bar to not handle active page, since active page updates progress bar through PAGE_PROGRESS events

* Revert "Change progress bar to not handle active page, since active page updates progress bar through PAGE_PROGRESS events"

This reverts commit 0500899.

* Modify initial loading styles and signals.

* Fix lint and types

* Change loading logic to depend on canplay events for media.  Suppress errors to ensure all elements have a chance to load.

* Refactor page load utility functions in amp-story

* Fix lint

* Move dispatch out of vsync

* Add whitespace to trigger Travis re-run

* Remove unnecessary whitespace

* Rename loadPromise vars

* Fix line length
RanAbram pushed a commit to RanAbram/amphtml that referenced this pull request Mar 12, 2018
* Change progress bar to not handle active page, since active page updates progress bar through PAGE_PROGRESS events

* Revert "Change progress bar to not handle active page, since active page updates progress bar through PAGE_PROGRESS events"

This reverts commit 0500899.

* Modify initial loading styles and signals.

* Fix lint and types

* Change loading logic to depend on canplay events for media.  Suppress errors to ensure all elements have a chance to load.

* Refactor page load utility functions in amp-story

* Fix lint

* Move dispatch out of vsync

* Add whitespace to trigger Travis re-run

* Remove unnecessary whitespace

* Rename loadPromise vars

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

Successfully merging this pull request may close these issues.

None yet

4 participants