33 lines
966 B
TypeScript
33 lines
966 B
TypeScript
/**
|
|
* 导航栏内容区高度(px)。
|
|
* 基于胶囊按钮位置计算:让 inner 的垂直中心与胶囊中心对齐,
|
|
* inner_height = (capsule.top - statusBarHeight) * 2 + capsule.height。
|
|
* 默认值 44 仅作兜底。
|
|
*/
|
|
|
|
let cachedInnerPx: number | null = null;
|
|
|
|
function computeInnerPx(): number {
|
|
try {
|
|
const { statusBarHeight } = wx.getWindowInfo();
|
|
const rect = wx.getMenuButtonBoundingClientRect();
|
|
const inner = (rect.top - statusBarHeight) * 2 + rect.height;
|
|
if (inner > 0 && Number.isFinite(inner)) {
|
|
return Math.round(inner);
|
|
}
|
|
} catch (e) {
|
|
// ignore, fallback below
|
|
}
|
|
return 44;
|
|
}
|
|
|
|
export function getNavInnerPx(): number {
|
|
if (cachedInnerPx === null) {
|
|
cachedInnerPx = computeInnerPx();
|
|
}
|
|
return cachedInnerPx;
|
|
}
|
|
|
|
/** 兼容旧调用:保留常量导出,启动时取一次胶囊几何。 */
|
|
export const NAV_INNER_PX = getNavInnerPx();
|