]> cat aescling's git repositories - mastodon.git/commitdiff
Change window resize handler to switch to/from mobile layout as soon as needed (...
authorThibG <thib@sitedethib.com>
Sun, 25 Aug 2019 13:48:50 +0000 (15:48 +0200)
committerEugen Rochko <eugen@zeonfederated.com>
Sun, 25 Aug 2019 13:48:50 +0000 (15:48 +0200)
app/javascript/mastodon/features/ui/index.js

index f0c3eff834ed10d2bc64452df16b269707c9160e..9d284c2216cf75ffc27df3ea2b1532e59df4abb4 100644 (file)
@@ -141,14 +141,24 @@ class SwitchingColumnsArea extends React.PureComponent {
     return location.state !== previewMediaState && location.state !== previewVideoState;
   }
 
-  handleResize = debounce(() => {
+  handleLayoutChange = debounce(() => {
     // The cached heights are no longer accurate, invalidate
     this.props.onLayoutChange();
-
-    this.setState({ mobile: isMobile(window.innerWidth) });
   }, 500, {
     trailing: true,
-  });
+  })
+
+  handleResize = () => {
+    const mobile = isMobile(window.innerWidth);
+
+    if (mobile !== this.state.mobile) {
+      this.handleLayoutChange.cancel();
+      this.props.onLayoutChange();
+      this.setState({ mobile });
+    } else {
+      this.handleLayoutChange();
+    }
+  }
 
   setRef = c => {
     this.node = c.getWrappedInstance();