fix: avoid native menu overlap

This commit is contained in:
czz
2026-05-07 16:20:22 +08:00
parent c293f7f970
commit 991b542b8c
2 changed files with 13 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
.device-page { .device-page {
position: relative; position: relative;
min-height: 100vh; min-height: 100vh;
padding: calc(var(--status-bar-height, 0px) + 24rpx) 24rpx 156rpx; padding: calc(var(--top-safe-height, 0px) + 24rpx) 24rpx 156rpx;
box-sizing: border-box; box-sizing: border-box;
background: linear-gradient(180deg, #1e2432 0%, #191f2c 100%); background: linear-gradient(180deg, #1e2432 0%, #191f2c 100%);
overflow: hidden; overflow: hidden;
@@ -37,6 +37,7 @@
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
padding-right: calc(var(--menu-safe-width, 0px) + 12rpx);
margin-bottom: 26rpx; margin-bottom: 26rpx;
} }

View File

@@ -63,12 +63,19 @@ export default function Index() {
const [bluetoothDevices, setBluetoothDevices] = useState<DeviceCandidate[]>([]); const [bluetoothDevices, setBluetoothDevices] = useState<DeviceCandidate[]>([]);
const [recentDeviceName, setRecentDeviceName] = useState(""); const [recentDeviceName, setRecentDeviceName] = useState("");
const [statusHint, setStatusHint] = useState("可通过扫码或蓝牙搜索完成设备绑定。"); const [statusHint, setStatusHint] = useState("可通过扫码或蓝牙搜索完成设备绑定。");
const [statusBarHeight, setStatusBarHeight] = useState(0); const [topSafeHeight, setTopSafeHeight] = useState(0);
const [menuSafeWidth, setMenuSafeWidth] = useState(0);
const discoveryTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null); const discoveryTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
useEffect(() => { useEffect(() => {
const windowInfo = typeof Taro.getWindowInfo === "function" ? Taro.getWindowInfo() : Taro.getSystemInfoSync(); const windowInfo = typeof Taro.getWindowInfo === "function" ? Taro.getWindowInfo() : Taro.getSystemInfoSync();
setStatusBarHeight(windowInfo.statusBarHeight || 0); const menuButtonRect =
typeof Taro.getMenuButtonBoundingClientRect === "function" ? Taro.getMenuButtonBoundingClientRect() : null;
const safeTop = menuButtonRect?.bottom || windowInfo.statusBarHeight || 0;
const safeRight = menuButtonRect ? windowInfo.windowWidth - menuButtonRect.left : 0;
setTopSafeHeight(safeTop);
setMenuSafeWidth(safeRight);
return () => { return () => {
if (discoveryTimerRef.current) { if (discoveryTimerRef.current) {
@@ -255,7 +262,8 @@ export default function Index() {
}; };
const pageStyle = { const pageStyle = {
"--status-bar-height": `${statusBarHeight}px` "--top-safe-height": `${topSafeHeight}px`,
"--menu-safe-width": `${menuSafeWidth}px`
} as CSSProperties; } as CSSProperties;
return ( return (