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

Disallowing resize of elements near top of viewport when viewport not scrolled #5774

Merged
merged 3 commits into from Feb 27, 2017
Merged

Disallowing resize of elements near top of viewport when viewport not scrolled #5774

merged 3 commits into from Feb 27, 2017

Conversation

tlong2
Copy link
Contributor

@tlong2 tlong2 commented Oct 24, 2016

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.

@tlong2 tlong2 changed the title Syncing commits Disallowing resize of things near top of viewport when viewport not scrolled Oct 24, 2016
@tlong2 tlong2 changed the title Disallowing resize of things near top of viewport when viewport not scrolled Disallowing resize of elements near top of viewport when viewport not scrolled Oct 24, 2016
@jridgewell
Copy link
Contributor

Do you have a demo page we could see the issue on?

/to @dvoytenko

@tlong2
Copy link
Contributor Author

tlong2 commented Oct 25, 2016

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:
There is a custom element (e.g. ) that is allowed to be placed near the top of the page. The implementation of it tries to increase its height using attemptChangeSize. If the were in the middle of the viewport then this would just not be allowed. But if the whole of the were within the top 10% of the viewport currently, then the resize would be allowed and the page would be scrolled, which would push the things above the (e.g. a nav bar) out of view.

@dvoytenko
Copy link
Contributor

@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.

@dvoytenko
Copy link
Contributor

In other words, let's get the repro case merged first :)

@tlong2
Copy link
Contributor Author

tlong2 commented Feb 22, 2017

@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/

@jridgewell
Copy link
Contributor

I think that's a bug with resetting the scrollTop, not the resize.

@tlong2
Copy link
Contributor Author

tlong2 commented Feb 22, 2017

There are two problems:

  1. Expanding things near the top of the page can push important things (like the menu) off the top. This is bad experience but is not the thing causing reflow.
  2. When we push something off the top of the page before page load completes a reflow occurs because on page load complete the scroll top gets reset to 0 by something

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.

@@ -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 &&
Copy link
Contributor

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.

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

@jridgewell
Copy link
Contributor

Expanding things near the top of the page can push important things (like the menu) off the top. This is bad experience but is not the thing causing reflow.

Perfect explanation, thanks.

@dvoytenko
Copy link
Contributor

@tlong2 Thanks! I'll take a look at the repro case.

@@ -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 &&
Copy link
Contributor

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

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

// 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
Copy link
Contributor

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?

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 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.

@googlebot
Copy link

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 cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@googlebot
Copy link

CLAs look good, thanks!

@dvoytenko
Copy link
Contributor

LGTM from me.

Copy link
Contributor

@jridgewell jridgewell left a 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.

@tlong2
Copy link
Contributor Author

tlong2 commented Feb 27, 2017

Looks like tests are all passing

@jridgewell jridgewell merged commit 5a4c7e2 into ampproject:master Feb 27, 2017
adelinamart pushed a commit that referenced this pull request Mar 1, 2017
… scrolled (#5774)

* changes

* Disallowing resize when vp not scrolled

* preventing size changes at top of viewport before scrolling.
mrjoro pushed a commit to mrjoro/amphtml that referenced this pull request Apr 28, 2017
… scrolled (ampproject#5774)

* changes

* Disallowing resize when vp not scrolled

* preventing size changes at top of viewport before scrolling.
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

5 participants