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

✨auto-lightbox carousels under experiment #20910

Merged
merged 15 commits into from Feb 26, 2019

Conversation

alanorozco
Copy link
Member

@alanorozco alanorozco commented Feb 18, 2019

  • Introduces criteria to accept any carousel that:
    1. Has one image on every slide
    2. Has no valid on=tap actions.
  • Since amp-img has to be measured against the slide element, some APIs are now async.
  • Introduces a mixed manual test for several cases.

return resolveFalse();
}

const slides = element.querySelectorAll('.amp-carousel-slide');
Copy link
Contributor

Choose a reason for hiding this comment

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

there is a race condition since it carousel extension is not loaded yet, we don't have this class.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, this runs after layoutCallback.

extensions/amp-auto-lightbox/0.1/carousel-criteria.js Outdated Show resolved Hide resolved
extensions/amp-auto-lightbox/0.1/carousel-criteria.js Outdated Show resolved Hide resolved
this.getSlidesFromCarousel_(carousel).then(slides => {
slides.forEach(slide => {
const shouldExcludeSlide = slide.hasAttribute('lightbox-exclude')
|| (slide.hasAttribute('lightbox')
const shouldExcludeSlide =
Copy link
Contributor

Choose a reason for hiding this comment

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

This boolean assignment is getting complex. Maybe split a subexpression into another named boolean?

const hasExistingLightbox = (slide.hasAttribute('lightbox') && 
    slide.getAttribute('lightbox') !== lightboxGroupId);
const shouldExcludeSlide = (slide.hasAttribute('lightbox-exclude') || hasExistingLightbox);

Copy link
Member Author

Choose a reason for hiding this comment

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

This assignment is exactly the same as before, just indented differently.

}
element = unwrappedFigureElement;
Copy link
Contributor

Choose a reason for hiding this comment

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

nice

{
id: 'amp-auto-lightbox-carousel',
name: 'Automatically detects carousels to group in a lightbox.',
spec: 'https://github.com/ampproject/amphtml/issues/20395',
Copy link
Contributor

Choose a reason for hiding this comment

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

sanity check: these github issues are the same as the above. possible copypaste error or intentional?

Copy link
Member Author

Choose a reason for hiding this comment

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

Intentional, not really necessary to divide the spec in Github according to our rollout.

extensions/amp-auto-lightbox/0.1/carousel-criteria.js Outdated Show resolved Hide resolved
static meetsSizingCriteria(img, slide) {
devAssert(img.tagName == 'AMP-IMG');

return img.getImpl().then(impl => new Promise(resolve => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe measureElement returns a Promise that contains the return value of the measurer function, so this new wrapper Promise is redundant. You can do

return img.getImpl().then(impl => {
  return impl.measureElement(() => {
    /*...*/
    return (imageArea/slideArea >= MIN_IMG_SLIDE_AREA_RATIO);
  });
});

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately the measure promise is shared by the entire batch so returning values is not possible.

extensions/amp-auto-lightbox/0.1/carousel-criteria.js Outdated Show resolved Hide resolved
extensions/amp-auto-lightbox/0.1/amp-auto-lightbox.js Outdated Show resolved Hide resolved
Copy link
Member Author

@alanorozco alanorozco left a comment

Choose a reason for hiding this comment

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

@aghassemi @cvializ Simplified per offline discussion and comments here. PTAL.

{
id: 'amp-auto-lightbox-carousel',
name: 'Automatically detects carousels to group in a lightbox.',
spec: 'https://github.com/ampproject/amphtml/issues/20395',
Copy link
Member Author

Choose a reason for hiding this comment

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

Intentional, not really necessary to divide the spec in Github according to our rollout.

this.getSlidesFromCarousel_(carousel).then(slides => {
slides.forEach(slide => {
const shouldExcludeSlide = slide.hasAttribute('lightbox-exclude')
|| (slide.hasAttribute('lightbox')
const shouldExcludeSlide =
Copy link
Member Author

Choose a reason for hiding this comment

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

This assignment is exactly the same as before, just indented differently.

return resolveFalse();
}

const slides = element.querySelectorAll('.amp-carousel-slide');
Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, this runs after layoutCallback.

static meetsSizingCriteria(img, slide) {
devAssert(img.tagName == 'AMP-IMG');

return img.getImpl().then(impl => new Promise(resolve => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately the measure promise is shared by the entire batch so returning values is not possible.

@ampproject ampproject deleted a comment Feb 22, 2019
Copy link
Contributor

@cvializ cvializ left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@aghassemi aghassemi left a comment

Choose a reason for hiding this comment

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

sorry for the late response, LGTM

@alanorozco alanorozco merged commit 420db9d into ampproject:master Feb 26, 2019
@alanorozco alanorozco deleted the lightbox-carousel branch February 26, 2019 06:43
noranazmy pushed a commit to noranazmy/amphtml that referenced this pull request Mar 22, 2019
* Introduces criteria to accept any carousel that:
    1. Has one image on every slide
    2. Has no valid `on=tap` actions.
* Since `amp-img` has to be measured against the slide element, some APIs are now async.
* Introduces a `mixed` manual test for several cases.
bramanudom pushed a commit to bramanudom/amphtml that referenced this pull request Mar 22, 2019
* Introduces criteria to accept any carousel that:
    1. Has one image on every slide
    2. Has no valid `on=tap` actions.
* Since `amp-img` has to be measured against the slide element, some APIs are now async.
* Introduces a `mixed` manual test for several cases.
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.

None yet

4 participants