mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-09-23 09:21:00 +02:00
add isTouchMobile to device
This commit is contained in:
@@ -473,14 +473,13 @@ 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,
|
||||||
|
isTouchMobile: false,
|
||||||
};
|
};
|
||||||
const DeviceContext = React.createContext<Device>(deviceContextInitialValue);
|
const DeviceContext = React.createContext<Device>(deviceContextInitialValue);
|
||||||
DeviceContext.displayName = "DeviceContext";
|
DeviceContext.displayName = "DeviceContext";
|
||||||
@@ -2451,7 +2450,6 @@ 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) {
|
||||||
@@ -2461,6 +2459,17 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private refreshTouchScreen = () => {
|
||||||
|
const previousIsTouchMobile = this.device.isTouchMobile;
|
||||||
|
const currentIsTouchMobile = this.isMobileOrTablet();
|
||||||
|
|
||||||
|
if (previousIsTouchMobile !== currentIsTouchMobile) {
|
||||||
|
this.device = { ...this.device, isTouchMobile: currentIsTouchMobile };
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
private refreshEditorBreakpoints = () => {
|
private refreshEditorBreakpoints = () => {
|
||||||
const container = this.excalidrawContainerRef.current;
|
const container = this.excalidrawContainerRef.current;
|
||||||
if (!container) {
|
if (!container) {
|
||||||
@@ -2480,7 +2489,6 @@ 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) {
|
||||||
@@ -2567,6 +2575,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
) {
|
) {
|
||||||
this.refreshViewportBreakpoints();
|
this.refreshViewportBreakpoints();
|
||||||
this.refreshEditorBreakpoints();
|
this.refreshEditorBreakpoints();
|
||||||
|
this.refreshTouchScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (supportsResizeObserver && this.excalidrawContainerRef.current) {
|
if (supportsResizeObserver && this.excalidrawContainerRef.current) {
|
||||||
@@ -2626,6 +2635,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
.getElementsIncludingDeleted()
|
.getElementsIncludingDeleted()
|
||||||
.forEach((element) => ShapeCache.delete(element));
|
.forEach((element) => ShapeCache.delete(element));
|
||||||
this.refreshViewportBreakpoints();
|
this.refreshViewportBreakpoints();
|
||||||
|
this.refreshTouchScreen();
|
||||||
this.updateDOMRect();
|
this.updateDOMRect();
|
||||||
if (!supportsResizeObserver) {
|
if (!supportsResizeObserver) {
|
||||||
this.refreshEditorBreakpoints();
|
this.refreshEditorBreakpoints();
|
||||||
|
@@ -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.editor.isTablet)}
|
renderSelectedShapeActions(device.isTouchMobile)}
|
||||||
</Stack.Col>
|
</Stack.Col>
|
||||||
{!appState.viewModeEnabled &&
|
{!appState.viewModeEnabled &&
|
||||||
appState.openDialog?.name !== "elementLinkSelector" && (
|
appState.openDialog?.name !== "elementLinkSelector" && (
|
||||||
|
@@ -879,14 +879,13 @@ 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;
|
||||||
|
isTouchMobile: boolean;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
export type FrameNameBounds = {
|
export type FrameNameBounds = {
|
||||||
|
Reference in New Issue
Block a user