From f9d2d45b242c1035a68ec3961ca05eafdad39aa2 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 3 Mar 2020 15:42:22 +0100 Subject: [PATCH 1/3] use relative scrolling to compensate when changing height --- src/components/structures/ScrollPanel.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/components/structures/ScrollPanel.js b/src/components/structures/ScrollPanel.js index 5121dd3f9d..72d5330451 100644 --- a/src/components/structures/ScrollPanel.js +++ b/src/components/structures/ScrollPanel.js @@ -705,17 +705,15 @@ export default createReactClass({ // the currently filled piece of the timeline if (trackedNode) { const oldTop = trackedNode.offsetTop; - // changing the height might change the scrollTop - // if the new height is smaller than the scrollTop. - // We calculate the diff that needs to be applied - // ourselves, so be sure to measure the - // scrollTop before changing the height. - const preexistingScrollTop = sn.scrollTop; itemlist.style.height = `${newHeight}px`; const newTop = trackedNode.offsetTop; const topDiff = newTop - oldTop; - sn.scrollTop = preexistingScrollTop + topDiff; - debuglog("updateHeight to", {newHeight, topDiff, preexistingScrollTop}); + // important to scroll by a relative amount as + // reading scrollTop and then setting it might + // yield out of date values and cause a jump + // when setting it + sn.scrollBy(0, topDiff); + debuglog("updateHeight to", {newHeight, topDiff}); } } }, From 223956a206f217e4d6ed5e2abfb1b0558b336414 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 3 Mar 2020 15:42:44 +0100 Subject: [PATCH 2/3] add comment how offset from bottom is calculated --- src/components/structures/ScrollPanel.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/structures/ScrollPanel.js b/src/components/structures/ScrollPanel.js index 72d5330451..548dd70748 100644 --- a/src/components/structures/ScrollPanel.js +++ b/src/components/structures/ScrollPanel.js @@ -765,6 +765,7 @@ export default createReactClass({ }, _topFromBottom(node) { + // current capped height - distance from top = distance from bottom of container to top of tracked element return this._itemlist.current.clientHeight - node.offsetTop; }, From 3e39cebb8f18006a5e20a44a45f3e21aaf59b17c Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 3 Mar 2020 15:44:59 +0100 Subject: [PATCH 3/3] also use relative scrolling when eh ... doing relative scrolling --- src/components/structures/ScrollPanel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/structures/ScrollPanel.js b/src/components/structures/ScrollPanel.js index 548dd70748..b81b3ebede 100644 --- a/src/components/structures/ScrollPanel.js +++ b/src/components/structures/ScrollPanel.js @@ -523,7 +523,7 @@ export default createReactClass({ scrollRelative: function(mult) { const scrollNode = this._getScrollNode(); const delta = mult * scrollNode.clientHeight * 0.5; - scrollNode.scrollTop = scrollNode.scrollTop + delta; + scrollNode.scrollBy(0, delta); this._saveScrollState(); },