mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-09-12 03:50:06 +02:00
add isTouchMobile to device
This commit is contained in:
@@ -473,10 +473,12 @@ const deviceContextInitialValue = {
|
|||||||
viewport: {
|
viewport: {
|
||||||
isMobile: false,
|
isMobile: false,
|
||||||
isLandscape: false,
|
isLandscape: false,
|
||||||
|
isTablet: false,
|
||||||
},
|
},
|
||||||
editor: {
|
editor: {
|
||||||
isMobile: false,
|
isMobile: false,
|
||||||
canFitSidebar: false,
|
canFitSidebar: false,
|
||||||
|
isTablet: false,
|
||||||
},
|
},
|
||||||
isTouchScreen: false,
|
isTouchScreen: false,
|
||||||
};
|
};
|
||||||
@@ -2422,6 +2424,12 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
return isMobile || isTouchMobile;
|
return isMobile || isTouchMobile;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private isTablet = (): boolean => {
|
||||||
|
const { clientWidth: viewportWidth } = document.body;
|
||||||
|
|
||||||
|
return this.isMobileOrTablet() && viewportWidth > MQ_MAX_WIDTH_PORTRAIT;
|
||||||
|
};
|
||||||
|
|
||||||
private isMobileBreakpoint = (width: number, height: number) => {
|
private isMobileBreakpoint = (width: number, height: number) => {
|
||||||
return (
|
return (
|
||||||
width < MQ_MAX_WIDTH_PORTRAIT ||
|
width < MQ_MAX_WIDTH_PORTRAIT ||
|
||||||
@@ -2443,6 +2451,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
const nextViewportState = updateObject(prevViewportState, {
|
const nextViewportState = updateObject(prevViewportState, {
|
||||||
isLandscape: viewportWidth > viewportHeight,
|
isLandscape: viewportWidth > viewportHeight,
|
||||||
isMobile: this.isMobileBreakpoint(viewportWidth, viewportHeight),
|
isMobile: this.isMobileBreakpoint(viewportWidth, viewportHeight),
|
||||||
|
isTablet: this.isTablet(),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (prevViewportState !== nextViewportState) {
|
if (prevViewportState !== nextViewportState) {
|
||||||
@@ -2471,6 +2480,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
const nextEditorState = updateObject(prevEditorState, {
|
const nextEditorState = updateObject(prevEditorState, {
|
||||||
isMobile: this.isMobileBreakpoint(editorWidth, editorHeight),
|
isMobile: this.isMobileBreakpoint(editorWidth, editorHeight),
|
||||||
canFitSidebar: editorWidth > sidebarBreakpoint,
|
canFitSidebar: editorWidth > sidebarBreakpoint,
|
||||||
|
isTablet: this.isTablet(),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (prevEditorState !== nextEditorState) {
|
if (prevEditorState !== nextEditorState) {
|
||||||
|
@@ -284,7 +284,7 @@ const LayerUI = ({
|
|||||||
<Stack.Col gap={6} className={clsx("App-menu_top__left")}>
|
<Stack.Col gap={6} className={clsx("App-menu_top__left")}>
|
||||||
{renderCanvasActions()}
|
{renderCanvasActions()}
|
||||||
{shouldRenderSelectedShapeActions &&
|
{shouldRenderSelectedShapeActions &&
|
||||||
renderSelectedShapeActions(device.isTouchScreen)}
|
renderSelectedShapeActions(device.editor.isTablet)}
|
||||||
</Stack.Col>
|
</Stack.Col>
|
||||||
{!appState.viewModeEnabled &&
|
{!appState.viewModeEnabled &&
|
||||||
appState.openDialog?.name !== "elementLinkSelector" && (
|
appState.openDialog?.name !== "elementLinkSelector" && (
|
||||||
|
@@ -879,9 +879,11 @@ export type Device = Readonly<{
|
|||||||
viewport: {
|
viewport: {
|
||||||
isMobile: boolean;
|
isMobile: boolean;
|
||||||
isLandscape: boolean;
|
isLandscape: boolean;
|
||||||
|
isTablet: boolean;
|
||||||
};
|
};
|
||||||
editor: {
|
editor: {
|
||||||
isMobile: boolean;
|
isMobile: boolean;
|
||||||
|
isTablet: boolean;
|
||||||
canFitSidebar: boolean;
|
canFitSidebar: boolean;
|
||||||
};
|
};
|
||||||
isTouchScreen: boolean;
|
isTouchScreen: boolean;
|
||||||
|
Reference in New Issue
Block a user