From 2b169b06f5659c1f348054c75cb390ef470f58b9 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 5 Jan 2016 10:58:01 +0000 Subject: [PATCH] Make ScrollPanel.isAtBottom more reliable Given we want to use isAtBottom to figure out whether to show 'unread messages' counts, we ought to return the current scroll state, rather than the saved one. This fixes vector-im/vector-web#576 --- src/components/structures/ScrollPanel.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/components/structures/ScrollPanel.js b/src/components/structures/ScrollPanel.js index 2c68562ada..4a45bf5a39 100644 --- a/src/components/structures/ScrollPanel.js +++ b/src/components/structures/ScrollPanel.js @@ -120,8 +120,15 @@ module.exports = React.createClass({ this.checkFillState(); }, + // return true if the content is fully scrolled down right now; else false. + // + // Note that if the content hasn't yet been fully populated, this may + // spuriously return true even if the user wanted to be looking at earlier + // content. So don't call it in render() cycles. isAtBottom: function() { - return this.scrollState && this.scrollState.atBottom; + var sn = this._getScrollNode(); + // + 1 here to avoid fractional pixel rounding errors + return sn.scrollHeight - sn.scrollTop <= sn.clientHeight + 1; }, // check the scroll state and send out backfill requests if necessary. @@ -213,9 +220,7 @@ module.exports = React.createClass({ // attribute. It is this token which is stored as the // 'lastDisplayedScrollToken'. - var sn = this._getScrollNode(); - // + 1 here to avoid fractional pixel rounding errors - var atBottom = sn.scrollHeight - sn.scrollTop <= sn.clientHeight + 1; + var atBottom = this.isAtBottom(); var itemlist = this.refs.itemlist; var wrapperRect = ReactDOM.findDOMNode(this).getBoundingClientRect();