浏览代码

fix: align MQ breakpoints and always use editor dimensions (#9991)

* fix: align MQ breakpoints and always use editor dimensions

* naming

* update snapshots
David Luzar 1 天之前
父节点
当前提交
a6a32b9b29
共有 3 个文件被更改,包括 10 次插入17 次删除
  1. 1 1
      excalidraw-app/tests/MobileMenu.test.tsx
  2. 2 5
      packages/common/src/constants.ts
  3. 7 11
      packages/excalidraw/components/App.tsx

+ 1 - 1
excalidraw-app/tests/MobileMenu.test.tsx

@@ -36,7 +36,7 @@ describe("Test MobileMenu", () => {
         },
         "isTouchScreen": false,
         "viewport": {
-          "isLandscape": false,
+          "isLandscape": true,
           "isMobile": true,
         },
       }

+ 2 - 5
packages/common/src/constants.ts

@@ -347,15 +347,12 @@ export const DEFAULT_UI_OPTIONS: AppProps["UIOptions"] = {
 
 // breakpoints
 // -----------------------------------------------------------------------------
-// md screen
-export const MQ_MAX_WIDTH_LANDSCAPE = 1000;
-export const MQ_MAX_HEIGHT_LANDSCAPE = 500;
 
 // mobile: up to 699px
-export const MQ_MAX_WIDTH_MOBILE = 699;
+export const MQ_MAX_MOBILE = 599;
 
 // tablets
-export const MQ_MIN_TABLET = 600; // lower bound (excludes phones)
+export const MQ_MIN_TABLET = MQ_MAX_MOBILE + 1; // lower bound (excludes phones)
 export const MQ_MAX_TABLET = 1400; // upper bound (excludes laptops/desktops)
 
 // desktop/laptop

+ 7 - 11
packages/excalidraw/components/App.tsx

@@ -100,9 +100,7 @@ import {
   MINIMUM_ARROW_SIZE,
   DOUBLE_TAP_POSITION_THRESHOLD,
   isMobileOrTablet,
-  MQ_MAX_WIDTH_MOBILE,
-  MQ_MAX_HEIGHT_LANDSCAPE,
-  MQ_MAX_WIDTH_LANDSCAPE,
+  MQ_MAX_MOBILE,
   MQ_MIN_TABLET,
   MQ_MAX_TABLET,
 } from "@excalidraw/common";
@@ -2423,10 +2421,8 @@ class App extends React.Component<AppProps, AppState> {
   };
 
   private isMobileBreakpoint = (width: number, height: number) => {
-    return (
-      width <= MQ_MAX_WIDTH_MOBILE ||
-      (height < MQ_MAX_HEIGHT_LANDSCAPE && width < MQ_MAX_WIDTH_LANDSCAPE)
-    );
+    const minSide = Math.min(width, height);
+    return minSide <= MQ_MAX_MOBILE;
   };
 
   private isTabletBreakpoint = (editorWidth: number, editorHeight: number) => {
@@ -2442,14 +2438,14 @@ class App extends React.Component<AppProps, AppState> {
       return;
     }
 
-    const { clientWidth: viewportWidth, clientHeight: viewportHeight } =
-      document.body;
+    const { width: editorWidth, height: editorHeight } =
+      container.getBoundingClientRect();
 
     const prevViewportState = this.device.viewport;
 
     const nextViewportState = updateObject(prevViewportState, {
-      isLandscape: viewportWidth > viewportHeight,
-      isMobile: this.isMobileBreakpoint(viewportWidth, viewportHeight),
+      isLandscape: editorWidth > editorHeight,
+      isMobile: this.isMobileBreakpoint(editorWidth, editorHeight),
     });
 
     if (prevViewportState !== nextViewportState) {