fix: respect status bar safe area
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
.device-page {
|
.device-page {
|
||||||
position: relative;
|
position: relative;
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
padding: 24rpx 24rpx 156rpx;
|
padding: calc(var(--status-bar-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;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Text, View } from "@tarojs/components";
|
import { Text, View } from "@tarojs/components";
|
||||||
import Taro from "@tarojs/taro";
|
import Taro from "@tarojs/taro";
|
||||||
|
import type { CSSProperties } from "react";
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import "./index.scss";
|
import "./index.scss";
|
||||||
|
|
||||||
@@ -62,9 +63,13 @@ 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 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();
|
||||||
|
setStatusBarHeight(windowInfo.statusBarHeight || 0);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
if (discoveryTimerRef.current) {
|
if (discoveryTimerRef.current) {
|
||||||
clearTimeout(discoveryTimerRef.current);
|
clearTimeout(discoveryTimerRef.current);
|
||||||
@@ -249,8 +254,12 @@ export default function Index() {
|
|||||||
await bindDevice(device.name, device.source === "ble" ? "蓝牙设备" : "演示设备");
|
await bindDevice(device.name, device.source === "ble" ? "蓝牙设备" : "演示设备");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const pageStyle = {
|
||||||
|
"--status-bar-height": `${statusBarHeight}px`
|
||||||
|
} as CSSProperties;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View className="device-page">
|
<View className="device-page" style={pageStyle}>
|
||||||
<View className="device-page__halo device-page__halo--large" />
|
<View className="device-page__halo device-page__halo--large" />
|
||||||
<View className="device-page__halo device-page__halo--small" />
|
<View className="device-page__halo device-page__halo--small" />
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user