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
Disallowing resize of elements near top of viewport when viewport not scrolled #5774
Conversation
Do you have a demo page we could see the issue on? /to @dvoytenko |
I don't have a demo page example. This was something I came across when experimenting with an extension I was playing around with. Basically the scenario is: |
@tlong2 Thanks! Let's however delay it until we are a bit deeper and closer to the feature-set we'd like. I'm pretty confident we can quickly bridge the gap, including via this PR. But I'd first like to get a good demonstrable state. |
In other words, let's get the repro case merged first :) |
@dvoytenko PTAL. The problem is now demonstrated by amp-auto-ads and this PR fixes the issue. Problem can be demonstrated/solution seen on http://amp.autoplaced.com/ |
I think that's a bug with resetting the scrollTop, not the resize. |
There are two problems:
This pull request fixes (1), which also has the effect of making (2) never be an issue for amp-auto-ads. Regardless of (2), (1) is still bad and this PR fixes it. |
src/service/resources-impl.js
Outdated
@@ -1052,9 +1053,13 @@ export class Resources { | |||
// an element's boundary is not changed above the viewport after | |||
// resize. | |||
resize = true; | |||
} else if (bottomDisplacedBoundary <= viewportRect.top + topOffset) { | |||
} else if (scrollTop > 0 && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For iOS, this might be set to 1
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Perfect explanation, thanks. |
@tlong2 Thanks! I'll take a look at the repro case. |
src/service/resources-impl.js
Outdated
@@ -1052,9 +1053,13 @@ export class Resources { | |||
// an element's boundary is not changed above the viewport after | |||
// resize. | |||
resize = true; | |||
} else if (bottomDisplacedBoundary <= viewportRect.top + topOffset) { | |||
} else if (scrollTop > 1 && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just use viewportRect.top
here instead of scrollTop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/service/resources-impl.js
Outdated
// 5. Elements above the viewport can only be resized if we are able | ||
// to compensate the height change by setting scrollTop. | ||
// to compensate the height change by setting scrollTop and only if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a good demo code to play with to see the effect and fix? Does this only affect elements that grow in size in reality?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The effect can be seen on http://amp.autoplaced.com/ if you enable the experiment: AMP.toggleExperiment('amp-auto-ads').
It's not easy to capture in an example page, as amp-auto-ads requires a remote configuration, which seems hard to mock out in an example page.
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
CLAs look good, thanks! |
LGTM from me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like test flake, please ping after it passes.
Looks like tests are all passing |
… scrolled (#5774) * changes * Disallowing resize when vp not scrolled * preventing size changes at top of viewport before scrolling.
… scrolled (ampproject#5774) * changes * Disallowing resize when vp not scrolled * preventing size changes at top of viewport before scrolling.
Modifying resources-impl.js so that an attemptChangeSize request doesn't resize elements near the top of the viewport when the viewport has not been scrolled.
Currently if the bottom of something is within the viewport but less than 10% of the viewport height from the top it is treated as though it is above the viewport. This can have the bad consequence that if something very small at the top of the page gets resized it can push things at the top (like the nav-bar) above the viewport and out of view, which is currently a bad and confusing experience for users, since this can happen at initial page load.