Skip to content

Commit c3aa49a

Browse files
use canvas width to update screen info
1 parent d94a667 commit c3aa49a

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

client/packages/lowcoder/src/comps/hooks/screenInfoComp.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { useCallback, useEffect, useState } from "react";
1+
import { useCallback, useEffect, useMemo, useState } from "react";
22
import { hookToStateComp } from "../generators/hookToComp";
3+
import { CanvasContainerID } from "@lowcoder-ee/index.sdk";
34

45
enum ScreenTypes {
56
Mobile = 'mobile',
@@ -19,9 +20,13 @@ type ScreenInfo = {
1920
}
2021

2122
function useScreenInfo() {
22-
const getDeviceType = () => {
23-
if (window.innerWidth < 768) return ScreenTypes.Mobile;
24-
if (window.innerWidth < 889) return ScreenTypes.Tablet;
23+
const canvasContainer = document.getElementById(CanvasContainerID);
24+
const canvas = document.getElementsByClassName('lowcoder-app-canvas')?.[0];
25+
const canvasWidth = canvasContainer?.clientWidth || canvas?.clientWidth;
26+
27+
const getDeviceType = (width: number) => {
28+
if (width < 768) return ScreenTypes.Mobile;
29+
if (width < 889) return ScreenTypes.Tablet;
2530
return ScreenTypes.Desktop;
2631
}
2732
const getFlagsByDeviceType = (deviceType: ScreenType) => {
@@ -41,16 +46,17 @@ function useScreenInfo() {
4146

4247
const getScreenInfo = useCallback(() => {
4348
const { innerWidth, innerHeight } = window;
44-
const deviceType = getDeviceType();
49+
const deviceType = getDeviceType(canvasWidth || window.innerWidth);
4550
const flags = getFlagsByDeviceType(deviceType);
4651

4752
return {
4853
width: innerWidth,
4954
height: innerHeight,
55+
canvasWidth,
5056
deviceType,
5157
...flags
5258
};
53-
}, [])
59+
}, [canvasWidth])
5460

5561
const [screenInfo, setScreenInfo] = useState<ScreenInfo>({});
5662

@@ -64,6 +70,10 @@ function useScreenInfo() {
6470
return () => window.removeEventListener('resize', updateScreenInfo);
6571
}, [ updateScreenInfo ])
6672

73+
useEffect(() => {
74+
updateScreenInfo();
75+
}, [canvasWidth]);
76+
6777
return screenInfo;
6878
}
6979

client/packages/lowcoder/src/pages/common/header.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
Layout,
2323
Left,
2424
Middle,
25-
MobileAppIcon,
2625
ModuleIcon,
2726
PackUpIcon,
2827
RefreshIcon,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy