about summary refs log tree commit diff
path: root/app/javascript
diff options
context:
space:
mode:
authorabcang <abcang1015@gmail.com>2017-08-30 00:06:19 +0900
committerEugen Rochko <eugen@zeonfederated.com>2017-08-29 17:06:19 +0200
commitf59ed3a4fafab776b4eeb92f805dfe1fecc17ee3 (patch)
tree953feb4641da8059f4807a57a7b5b6d2caea0662 /app/javascript
parent7be620775eef7fe73a32c5507b59ae7c8f560517 (diff)
Scroll smoothly to the right (#4735)
Diffstat (limited to 'app/javascript')
-rw-r--r--app/javascript/mastodon/features/ui/components/columns_area.js16
-rw-r--r--app/javascript/mastodon/scroll.js2
2 files changed, 16 insertions, 2 deletions
diff --git a/app/javascript/mastodon/features/ui/components/columns_area.js b/app/javascript/mastodon/features/ui/components/columns_area.js
index b8f3a5ccb..2dd71dbc6 100644
--- a/app/javascript/mastodon/features/ui/components/columns_area.js
+++ b/app/javascript/mastodon/features/ui/components/columns_area.js
@@ -12,6 +12,7 @@ import ColumnLoading from './column_loading';
 import BundleColumnError from './bundle_column_error';
 import { Compose, Notifications, HomeTimeline, CommunityTimeline, PublicTimeline, HashtagTimeline, FavouritedStatuses } from '../../ui/util/async-components';
 
+import detectPassiveEvents from 'detect-passive-events';
 import { scrollRight } from '../../../scroll';
 
 const componentMap = {
@@ -47,6 +48,7 @@ export default class ColumnsArea extends ImmutablePureComponent {
   }
 
   componentDidMount() {
+    this.node.addEventListener('wheel', this.handleWheel,  detectPassiveEvents ? { passive: true } : false);
     this.lastIndex = getIndex(this.context.router.history.location.pathname);
     this.setState({ shouldAnimate: true });
   }
@@ -56,9 +58,13 @@ export default class ColumnsArea extends ImmutablePureComponent {
     this.setState({ shouldAnimate: true });
   }
 
+  componentWillUnmount () {
+    this.node.removeEventListener('wheel', this.handleWheel);
+  }
+
   handleChildrenContentChange() {
     if (!this.props.singleColumn) {
-      scrollRight(this.node);
+      scrollRight(this.node, this.node.scrollWidth - window.innerWidth);
     }
   }
 
@@ -82,6 +88,14 @@ export default class ColumnsArea extends ImmutablePureComponent {
     }
   }
 
+  handleWheel = () => {
+    if (typeof this._interruptScrollAnimation !== 'function') {
+      return;
+    }
+
+    this._interruptScrollAnimation();
+  }
+
   setRef = (node) => {
     this.node = node;
   }
diff --git a/app/javascript/mastodon/scroll.js b/app/javascript/mastodon/scroll.js
index 44f95b17f..2af07e0fb 100644
--- a/app/javascript/mastodon/scroll.js
+++ b/app/javascript/mastodon/scroll.js
@@ -26,5 +26,5 @@ const scroll = (node, key, target) => {
   };
 };
 
-export const scrollRight = (node) => scroll(node, 'scrollLeft', node.scrollWidth);
+export const scrollRight = (node, position) => scroll(node, 'scrollLeft', position);
 export const scrollTop = (node) => scroll(node, 'scrollTop', 0);