keep track of current updateHeight request outside of method

it's only called from one place
pull/21833/head
Bruno Windels 2019-03-19 16:53:23 +01:00
parent 2bcced72ad
commit 88f039fe44
1 changed files with 31 additions and 35 deletions

View File

@ -578,7 +578,7 @@ module.exports = React.createClass({
};
},
_restoreSavedScrollState: function() {
_restoreSavedScrollState: async function() {
const scrollState = this.scrollState;
if (scrollState.stuckAtBottom) {
@ -598,21 +598,20 @@ module.exports = React.createClass({
}
// TODO: also call _updateHeight if not already in progress
if (!this._heightUpdateInProgress) {
const heightDiff = this._getMessagesHeight() - this._getListHeight();
if (heightDiff > 0) {
this._updateHeight();
this._heightUpdateInProgress = true;
try {
await this._updateHeight();
} finally {
this._heightUpdateInProgress = false;
}
}
},
// need a better name that also indicates this will change scrollTop? Rebalance height? Reveal content?
async _updateHeight() {
if (this._heightUpdateInProgress) {
return;
}
this._heightUpdateInProgress = true;
try {
const startTs = Date.now();
// wait until user has stopped scrolling
if (this._scrollTimeout.isRunning()) {
debuglog("xxx updateHeight waiting for scrolling to end ... ");
await this._scrollTimeout.finished();
}
@ -628,7 +627,7 @@ module.exports = React.createClass({
if (this.scrollState.stuckAtBottom) {
itemlist.style.height = `${newHeight}px`;
sn.scrollTop = sn.scrollHeight;
debuglog("updateHeight to", newHeight);
debuglog("xxx updateHeight to", newHeight);
} else {
const trackedNode = this._getTrackedNode();
const oldTop = trackedNode.offsetTop;
@ -636,10 +635,7 @@ module.exports = React.createClass({
const newTop = trackedNode.offsetTop;
const topDiff = newTop - oldTop;
sn.scrollTop = sn.scrollTop + topDiff;
debuglog("updateHeight to", newHeight, topDiff);
}
} finally {
this._heightUpdateInProgress = false;
debuglog("xxx updateHeight to", newHeight, topDiff, Date.now() - startTs);
}
},