about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/components
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2019-01-08 21:26:23 +0100
committerThibG <thib@sitedethib.com>2019-01-10 12:09:12 +0100
commit825decbf9ecfb60228cfa292a5d94d0ddc9d5998 (patch)
tree17d0d716817ed49df01f18c23ca07318a54e527a /app/javascript/flavours/glitch/components
parent19c64a49f7da7e4131e5090a24d3056eaff490db (diff)
[Glitch] Identify manual scrolling to cancel scroll to top reset on mouse idle
Port 2f86fc5e0a45eb2002d4b481ae093197ad523479 to glitch-soc
Diffstat (limited to 'app/javascript/flavours/glitch/components')
-rw-r--r--app/javascript/flavours/glitch/components/scrollable_list.js21
1 files changed, 17 insertions, 4 deletions
diff --git a/app/javascript/flavours/glitch/components/scrollable_list.js b/app/javascript/flavours/glitch/components/scrollable_list.js
index 520749529..09a22f633 100644
--- a/app/javascript/flavours/glitch/components/scrollable_list.js
+++ b/app/javascript/flavours/glitch/components/scrollable_list.js
@@ -58,6 +58,13 @@ export default class ScrollableList extends PureComponent {
       } else if (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, {
     trailing: true,
@@ -65,8 +72,16 @@ export default class ScrollableList extends PureComponent {
 
   mouseIdleTimer = null;
   mouseMovedRecently = false;
+  lastScrollWasSynthetic = false;
   scrollToTopOnMouseIdle = false;
 
+  setScrollTop = newScrollTop => {
+    if (this.node.scrollTop !== newScrollTop) {
+      this.lastScrollWasSynthetic = true;
+      this.node.scrollTop = newScrollTop;
+    }
+  };
+
   clearMouseIdleTimer = () => {
     if (this.mouseIdleTimer === null) {
       return;
@@ -97,7 +112,7 @@ export default class ScrollableList extends PureComponent {
 
   handleMouseIdle = () => {
     if (this.scrollToTopOnMouseIdle) {
-      this.node.scrollTop = 0;
+      this.setScrollTop(0);
     }
     this.mouseMovedRecently = false;
     this.scrollToTopOnMouseIdle = false;
@@ -123,9 +138,7 @@ export default class ScrollableList extends PureComponent {
   updateScrollBottom = (snapshot) => {
     const newScrollTop = this.node.scrollHeight - snapshot;
 
-    if (this.node.scrollTop !== newScrollTop) {
-      this.node.scrollTop = newScrollTop;
-    }
+    this.setScrollTop(newScrollTop);
   }
 
   getSnapshotBeforeUpdate (prevProps, prevState) {