列表
This commit is contained in:
@@ -1,13 +1,39 @@
|
||||
import Taro from "@tarojs/taro";
|
||||
|
||||
export const getNavbarHeight = (): { statusBarHeight: number; navbarHeight: number; totalHeight: number; } => {
|
||||
export const getNavbarHeight = (): { statusBarHeight: number; navBarHeight: number; totalHeight: number; } => {
|
||||
// 1. 获取系统信息,包含状态栏高度
|
||||
const systemInfo = Taro.getSystemInfoSync();
|
||||
const statusBarHeight = systemInfo?.statusBarHeight || 0;
|
||||
const statusBarHeight = systemInfo.statusBarHeight || 0;
|
||||
|
||||
|
||||
const isIOS = systemInfo.platform === "ios";
|
||||
const navbarHeight = isIOS ? 44 : 48;
|
||||
const isIPad = systemInfo.model?.toLowerCase().includes('ipad') ||
|
||||
(systemInfo.platform === 'ios' && systemInfo.screenWidth >= 768);
|
||||
|
||||
// 2. 获取胶囊按钮位置信息(用于计算导航栏高度)
|
||||
const menuButtonInfo = Taro.getMenuButtonBoundingClientRect();
|
||||
|
||||
let navBarHeight = 44 // 默认导航栏高度
|
||||
|
||||
if (menuButtonInfo && menuButtonInfo.top) {
|
||||
// 计算导航栏高度公式
|
||||
navBarHeight = (menuButtonInfo.top - statusBarHeight) * 2 + menuButtonInfo.height
|
||||
} else {
|
||||
// 胶囊按钮信息不可用时,使用默认值
|
||||
if (isIPad) {
|
||||
navBarHeight = 50; // iPad 上的导航栏高度通常更高
|
||||
} else if (isIOS) {
|
||||
navBarHeight = 44; // iPhone 导航栏高度
|
||||
} else {
|
||||
navBarHeight = 48; // Android 导航栏高度
|
||||
}
|
||||
}
|
||||
|
||||
const totalHeight = statusBarHeight + navBarHeight;
|
||||
|
||||
return {
|
||||
statusBarHeight,
|
||||
navbarHeight,
|
||||
totalHeight: statusBarHeight + navbarHeight,
|
||||
navBarHeight,
|
||||
totalHeight,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user