about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorSorin Davidoi <sorin.davidoi@gmail.com>2017-07-29 21:20:34 +0200
committerEugen Rochko <eugen@zeonfederated.com>2017-07-29 21:20:34 +0200
commit4f04981dde71ab621a6d0c8cff7aade5f5efb649 (patch)
tree7486532b19bddc9b2c3c982fcf58707e17eb811d /app
parent990cea471eceadf3905ff4a41df034f4ae63889c (diff)
feat(tabs_bar): Avoid optimization for non-touch devices (#4444)
* fix(tabs_bar): Check if transition is necessary

* feat(tabs_bar): Only apply optimization for touch devices
Diffstat (limited to 'app')
-rw-r--r--app/javascript/mastodon/features/ui/components/tabs_bar.js50
1 files changed, 29 insertions, 21 deletions
diff --git a/app/javascript/mastodon/features/ui/components/tabs_bar.js b/app/javascript/mastodon/features/ui/components/tabs_bar.js
index e4061cdc4..af9e6bf45 100644
--- a/app/javascript/mastodon/features/ui/components/tabs_bar.js
+++ b/app/javascript/mastodon/features/ui/components/tabs_bar.js
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
 import NavLink from 'react-router-dom/NavLink';
 import { FormattedMessage, injectIntl } from 'react-intl';
 import { debounce } from 'lodash';
+import { isUserTouching } from '../../../is_mobile';
 
 export const links = [
   <NavLink className='tabs-bar__link primary' to='/statuses/new' data-preview-title-id='tabs_bar.compose' data-preview-icon='pencil' ><i className='fa fa-fw fa-pencil' /><FormattedMessage id='tabs_bar.compose' defaultMessage='Compose' /></NavLink>,
@@ -39,27 +40,34 @@ export default class TabsBar extends React.Component {
   }
 
   handleClick = (e) => {
-    e.preventDefault();
-    e.persist();
-
-    requestAnimationFrame(() => {
-      const tabs = Array(...this.node.querySelectorAll('.tabs-bar__link'));
-      const currentTab = tabs.find(tab => tab.classList.contains('active'));
-      const nextTab = tabs.find(tab => tab.contains(e.target));
-      const { props: { to } } = links[Array(...this.node.childNodes).indexOf(nextTab)];
-
-      if (currentTab) {
-        currentTab.classList.remove('active');
-      }
-
-      const listener = debounce(() => {
-        nextTab.removeEventListener('transitionend', listener);
-        this.context.router.history.push(to);
-      }, 50);
-
-      nextTab.addEventListener('transitionend', listener);
-      nextTab.classList.add('active');
-    });
+    // Only apply optimization for touch devices, which we assume are slower
+    // We thus avoid the 250ms delay for non-touch devices and the lag for touch devices
+    if (isUserTouching()) {
+      e.preventDefault();
+      e.persist();
+
+      requestAnimationFrame(() => {
+        const tabs = Array(...this.node.querySelectorAll('.tabs-bar__link'));
+        const currentTab = tabs.find(tab => tab.classList.contains('active'));
+        const nextTab = tabs.find(tab => tab.contains(e.target));
+        const { props: { to } } = links[Array(...this.node.childNodes).indexOf(nextTab)];
+
+
+        if (currentTab !== nextTab) {
+          if (currentTab) {
+            currentTab.classList.remove('active');
+          }
+
+          const listener = debounce(() => {
+            nextTab.removeEventListener('transitionend', listener);
+            this.context.router.history.push(to);
+          }, 50);
+
+          nextTab.addEventListener('transitionend', listener);
+          nextTab.classList.add('active');
+        }
+      });
+    }
 
   }