keep track of current updateHeight request outside of method
it's only called from one placepull/21833/head
parent
2bcced72ad
commit
88f039fe44
|
@ -578,7 +578,7 @@ module.exports = React.createClass({
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
_restoreSavedScrollState: function() {
|
_restoreSavedScrollState: async function() {
|
||||||
const scrollState = this.scrollState;
|
const scrollState = this.scrollState;
|
||||||
|
|
||||||
if (scrollState.stuckAtBottom) {
|
if (scrollState.stuckAtBottom) {
|
||||||
|
@ -598,21 +598,20 @@ module.exports = React.createClass({
|
||||||
}
|
}
|
||||||
// TODO: also call _updateHeight if not already in progress
|
// TODO: also call _updateHeight if not already in progress
|
||||||
if (!this._heightUpdateInProgress) {
|
if (!this._heightUpdateInProgress) {
|
||||||
const heightDiff = this._getMessagesHeight() - this._getListHeight();
|
this._heightUpdateInProgress = true;
|
||||||
if (heightDiff > 0) {
|
try {
|
||||||
this._updateHeight();
|
await this._updateHeight();
|
||||||
|
} finally {
|
||||||
|
this._heightUpdateInProgress = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// need a better name that also indicates this will change scrollTop? Rebalance height? Reveal content?
|
// need a better name that also indicates this will change scrollTop? Rebalance height? Reveal content?
|
||||||
async _updateHeight() {
|
async _updateHeight() {
|
||||||
if (this._heightUpdateInProgress) {
|
const startTs = Date.now();
|
||||||
return;
|
|
||||||
}
|
|
||||||
this._heightUpdateInProgress = true;
|
|
||||||
try {
|
|
||||||
// wait until user has stopped scrolling
|
// wait until user has stopped scrolling
|
||||||
if (this._scrollTimeout.isRunning()) {
|
if (this._scrollTimeout.isRunning()) {
|
||||||
|
debuglog("xxx updateHeight waiting for scrolling to end ... ");
|
||||||
await this._scrollTimeout.finished();
|
await this._scrollTimeout.finished();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -628,7 +627,7 @@ module.exports = React.createClass({
|
||||||
if (this.scrollState.stuckAtBottom) {
|
if (this.scrollState.stuckAtBottom) {
|
||||||
itemlist.style.height = `${newHeight}px`;
|
itemlist.style.height = `${newHeight}px`;
|
||||||
sn.scrollTop = sn.scrollHeight;
|
sn.scrollTop = sn.scrollHeight;
|
||||||
debuglog("updateHeight to", newHeight);
|
debuglog("xxx updateHeight to", newHeight);
|
||||||
} else {
|
} else {
|
||||||
const trackedNode = this._getTrackedNode();
|
const trackedNode = this._getTrackedNode();
|
||||||
const oldTop = trackedNode.offsetTop;
|
const oldTop = trackedNode.offsetTop;
|
||||||
|
@ -636,10 +635,7 @@ module.exports = React.createClass({
|
||||||
const newTop = trackedNode.offsetTop;
|
const newTop = trackedNode.offsetTop;
|
||||||
const topDiff = newTop - oldTop;
|
const topDiff = newTop - oldTop;
|
||||||
sn.scrollTop = sn.scrollTop + topDiff;
|
sn.scrollTop = sn.scrollTop + topDiff;
|
||||||
debuglog("updateHeight to", newHeight, topDiff);
|
debuglog("xxx updateHeight to", newHeight, topDiff, Date.now() - startTs);
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
this._heightUpdateInProgress = false;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue