Identify manual scrolling to cancel scroll to top reset on mouse idle (#9245)

pull/813/head^2
Les Orchard 2018-11-09 12:06:43 -05:00 committed by Eugen Rochko
parent 08b3de4d5e
commit 2f86fc5e0a
1 changed files with 17 additions and 6 deletions

View File

@ -59,6 +59,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,
@ -66,8 +73,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;
@ -99,7 +114,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;
@ -132,11 +147,7 @@ export default class ScrollableList extends PureComponent {
// Reset the scroll position when a new child comes in in order not to // Reset the scroll position when a new child comes in in order not to
// jerk the scrollbar around if you're already scrolled down the page. // jerk the scrollbar around if you're already scrolled down the page.
if (snapshot !== null) { if (snapshot !== null) {
const newScrollTop = this.node.scrollHeight - snapshot; this.setScrollTop(this.node.scrollHeight - snapshot);
if (this.node.scrollTop !== newScrollTop) {
this.node.scrollTop = newScrollTop;
}
} }
} }