[Glitch] Identify manual scrolling to cancel scroll to top reset on mouse idle

Port 2f86fc5e0a to glitch-soc
This commit is contained in:
Thibaut Girka 2019-01-08 21:26:23 +01:00 committed by ThibG
parent 19c64a49f7
commit 825decbf9e

View file

@ -58,6 +58,13 @@ export default class ScrollableList extends PureComponent {
} else if (this.props.onScroll) { } else if (this.props.onScroll) {
this.props.onScroll(); this.props.onScroll();
} }
if (!this.lastScrollWasSynthetic) {
// If the last scroll wasn't caused by setScrollTop(), assume it was
// intentional and cancel any pending scroll reset on mouse idle
this.scrollToTopOnMouseIdle = false;
}
this.lastScrollWasSynthetic = false;
} }
}, 150, { }, 150, {
trailing: true, trailing: true,
@ -65,8 +72,16 @@ export default class ScrollableList extends PureComponent {
mouseIdleTimer = null; mouseIdleTimer = null;
mouseMovedRecently = false; mouseMovedRecently = false;
lastScrollWasSynthetic = false;
scrollToTopOnMouseIdle = false; scrollToTopOnMouseIdle = false;
setScrollTop = newScrollTop => {
if (this.node.scrollTop !== newScrollTop) {
this.lastScrollWasSynthetic = true;
this.node.scrollTop = newScrollTop;
}
};
clearMouseIdleTimer = () => { clearMouseIdleTimer = () => {
if (this.mouseIdleTimer === null) { if (this.mouseIdleTimer === null) {
return; return;
@ -97,7 +112,7 @@ export default class ScrollableList extends PureComponent {
handleMouseIdle = () => { handleMouseIdle = () => {
if (this.scrollToTopOnMouseIdle) { if (this.scrollToTopOnMouseIdle) {
this.node.scrollTop = 0; this.setScrollTop(0);
} }
this.mouseMovedRecently = false; this.mouseMovedRecently = false;
this.scrollToTopOnMouseIdle = false; this.scrollToTopOnMouseIdle = false;
@ -123,9 +138,7 @@ export default class ScrollableList extends PureComponent {
updateScrollBottom = (snapshot) => { updateScrollBottom = (snapshot) => {
const newScrollTop = this.node.scrollHeight - snapshot; const newScrollTop = this.node.scrollHeight - snapshot;
if (this.node.scrollTop !== newScrollTop) { this.setScrollTop(newScrollTop);
this.node.scrollTop = newScrollTop;
}
} }
getSnapshotBeforeUpdate (prevProps, prevState) { getSnapshotBeforeUpdate (prevProps, prevState) {