Skip to content

Commit

Permalink
webview: Fix small scroll issues with message list
Browse files Browse the repository at this point in the history
Fixes zulip#3301

When showing/hiding UnreadNotice the message list scroll position
is moved by the height of that panel.

This (and other similar problems) can be fixed by a sophisticated
algorithm that 'anchors' the scroll position of the webview to the
bottom instead of the default to top. That turned out to be a much
more tricky solution, but a much simpler one that is a subset of
it would do the trick for now.

We add an event handler on the webview's 'resize' event. This will
be called in these situations:
 1. the keyboard is shown/hidden
 2. the phone orientation is changed
 3. the compose box shows/hides the topic input
 4. the UnreadNotice is shown/hidden

This code is an effective fix for (4)
I was a bit concerned that (3) might be negatively affected by
the fix but after testing it few times I think the behavior is an
improvement.

Not only that but we should look for even more cases where we can
scroll to the very bottom of the list (and maybe expand the 100px
distance that triggers it)
  • Loading branch information
borisyankov committed Jan 21, 2019
1 parent 400f4ac commit 2a2f5ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/webview/js/generatedEs3.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,4 +522,7 @@ documentBody.addEventListener('touchmove', function (e) {
documentBody.addEventListener('drag', function (e) {
lastTouchEventTimestamp = 0;
});
window.addEventListener('resize', function (event) {
scrollToBottomIfNearEnd();
});
`;
4 changes: 4 additions & 0 deletions src/webview/js/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,3 +684,7 @@ documentBody.addEventListener('touchmove', (e: TouchEvent) => {
documentBody.addEventListener('drag', (e: DragEvent) => {
lastTouchEventTimestamp = 0;
});

window.addEventListener('resize', (event) => {
scrollToBottomIfNearEnd();
});

0 comments on commit 2a2f5ea

Please sign in to comment.