]> cat aescling's git repositories - mastodon.git/commitdiff
Improve swiping (#4188)
authorSorin Davidoi <sorin.davidoi@gmail.com>
Thu, 13 Jul 2017 22:49:01 +0000 (00:49 +0200)
committerEugen Rochko <eugen@zeonfederated.com>
Thu, 13 Jul 2017 22:49:01 +0000 (00:49 +0200)
* feat(components/columns_area): Toggle animation settings

* fix(components/media_modal): Center non-visible views

* fix(components/media_modal): Check for null

* refactor(columns_area): Better logic

app/javascript/mastodon/features/ui/components/columns_area.js
app/javascript/styles/components.scss

index cbc185a7d60c906f807773be58b4a04a108d5350..ef9a1552236d32c18e7f427b02f22905c801da8c 100644 (file)
@@ -32,12 +32,19 @@ export default class ColumnsArea extends ImmutablePureComponent {
     children: PropTypes.node,
   };
 
+  componentDidUpdate() {
+    this.lastIndex = getIndex(this.context.router.history.location.pathname);
+  }
+
   handleSwipe = (index) => {
-    window.requestAnimationFrame(() => {
-      window.requestAnimationFrame(() => {
-        this.context.router.history.push(getLink(index));
-      });
-    });
+    this.pendingIndex = index;
+  }
+
+  handleAnimationEnd = () => {
+    if (typeof this.pendingIndex === 'number') {
+      this.context.router.history.push(getLink(this.pendingIndex));
+      this.pendingIndex = null;
+    }
   }
 
   renderView = (link, index) => {
@@ -68,10 +75,11 @@ export default class ColumnsArea extends ImmutablePureComponent {
     const { columns, children, singleColumn } = this.props;
 
     const columnIndex = getIndex(this.context.router.history.location.pathname);
+    const shouldAnimate = Math.abs(this.lastIndex - columnIndex) === 1;
 
     if (singleColumn) {
       return columnIndex !== -1 ? (
-        <ReactSwipeableViews index={columnIndex} onChangeIndex={this.handleSwipe} animateTransitions={false} style={{ height: '100%' }}>
+        <ReactSwipeableViews index={columnIndex} onChangeIndex={this.handleSwipe} onTransitionEnd={this.handleAnimationEnd} animateTransitions={shouldAnimate} springConfig={{ duration: '400ms', delay: '0s', easeFunction: 'ease' }} style={{ height: '100%' }}>
           {links.map(this.renderView)}
         </ReactSwipeableViews>
       ) : <div className='columns-area'>{children}</div>;
index bcf7ba4e0174f47d55f2fd813d60974e22e3eb92..0face646dde7b0239ccd984ec1a808f248d1185c 100644 (file)
 }
 
 .react-swipeable-view-container > * {
+  display: flex;
+  align-items: center;
   height: 100%;
 }