Skip to content

Commit

Permalink
webview js: Don't scroll on resize when *beyond* the bottom, either.
Browse files Browse the repository at this point in the history
As the code comments (which we added in the last few commits) explain:
when the viewport grows, we generally want to scroll up to keep its
bottom edge aligned within the content, but we want to skip that when
we're at the very bottom.

If we're at the bottom and scroll up anyway, the effect would be
exactly the symptoms in zulip#3301.

It turns out that when we're at the bottom, the `scrollTop` value may
not actually quite line up with where you'd think it should be.
Empirically:
 * On iOS (in Safari), it tends to be 1px beyond the bottom.
 * On Android (in Chrome), it's not an integer, and can be a fraction
   of a px either beyond or short of the bottom.

So, allow for that when checking to see if we're at the bottom.

Thanks to Vishwesh for suggesting a related direction in zulip#4003.

Fixes: zulip#3301
  • Loading branch information
gnprice committed Apr 15, 2020
1 parent cb1ff3e commit 24a052f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/webview/js/generatedEs3.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ var compiledWebviewJs = (function (exports) {
viewportHeight = documentBody.clientHeight;
var maxScrollTop = documentBody.scrollHeight - documentBody.clientHeight;
if (documentBody.scrollTop === maxScrollTop) {
if (documentBody.scrollTop >= maxScrollTop - 1) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/webview/js/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ window.addEventListener('resize', event => {
//
// If that happened, we'll be at the very bottom now.
const maxScrollTop = documentBody.scrollHeight - documentBody.clientHeight;
if (documentBody.scrollTop === maxScrollTop) {
// We're at the very bottom of the content. Don't scroll.
if (documentBody.scrollTop >= maxScrollTop - 1) {
// We're at (or beyond) the very bottom of the content. Don't scroll.
//
// This does mean if you're near the bottom, and then the viewport grows
// by more than that distance, you'll wind up at the very bottom instead
Expand Down

0 comments on commit 24a052f

Please sign in to comment.