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

webview, js: Only scroll on resize when !isNearBottom(). #4003

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/webview/js/generatedEs3.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,21 @@ var compiledWebviewJs = (function (exports) {
}
};

var isNearBottom = function isNearBottom() {
return documentBody.scrollHeight - 100 < documentBody.scrollTop + documentBody.clientHeight;
};

var viewportHeight = documentBody.clientHeight;
window.addEventListener('resize', function (event) {
var difference = viewportHeight - documentBody.clientHeight;

if (documentBody.scrollHeight !== documentBody.scrollTop + documentBody.clientHeight) {
window.scrollBy({
left: 0,
top: difference
});
if (isNearBottom() && difference > 0 || !isNearBottom()) {
window.scrollBy({
left: 0,
top: difference
});
}
}

viewportHeight = documentBody.clientHeight;
Expand Down Expand Up @@ -325,10 +331,6 @@ var compiledWebviewJs = (function (exports) {
});
};

var isNearBottom = function isNearBottom() {
return documentBody.scrollHeight - 100 < documentBody.scrollTop + documentBody.clientHeight;
};

var scrollToBottomIfNearEnd = function scrollToBottomIfNearEnd() {
if (isNearBottom()) {
scrollToBottom();
Expand Down
10 changes: 6 additions & 4 deletions src/webview/js/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,18 @@ const showHideElement = (elementId: string, show: boolean) => {
}
};

const isNearBottom = (): boolean =>
documentBody.scrollHeight - 100 < documentBody.scrollTop + documentBody.clientHeight;

/* Cached to avoid re-looking it up all the time. */
let viewportHeight = documentBody.clientHeight;

window.addEventListener('resize', event => {
const difference = viewportHeight - documentBody.clientHeight;
if (documentBody.scrollHeight !== documentBody.scrollTop + documentBody.clientHeight) {
window.scrollBy({ left: 0, top: difference });
if ((isNearBottom() && difference > 0) || !isNearBottom()) {
window.scrollBy({ left: 0, top: difference });
}
}
viewportHeight = documentBody.clientHeight;
});
Expand Down Expand Up @@ -431,9 +436,6 @@ const scrollToBottom = () => {
window.scroll({ left: 0, top: documentBody.scrollHeight, behavior: 'smooth' });
};

const isNearBottom = (): boolean =>
documentBody.scrollHeight - 100 < documentBody.scrollTop + documentBody.clientHeight;

const scrollToBottomIfNearEnd = () => {
if (isNearBottom()) {
scrollToBottom();
Expand Down