safe-area.uts
731 Bytes
/**
* 与窗口安全区/状态栏对齐的顶部 inset(px),用于自定义导航栏占位。
* 优先 safeAreaInsets.top,其次 safeArea.top,最后 statusBarHeight。
*/
export function calcWindowTopInsetPx(info: GetWindowInfoResult): number {
let topInset = 0
const insets = info.safeAreaInsets
if (insets != null) {
const t = insets.top
if (t != null && t > 0) {
topInset = Math.round(t)
}
}
if (topInset <= 0) {
const safe = info.safeArea
if (safe != null) {
const st = safe.top
if (st != null && st > 0) {
topInset = Math.round(st)
}
}
}
if (topInset <= 0) {
const sb = info.statusBarHeight
if (sb != null && sb > 0) {
topInset = Math.round(sb)
}
}
return topInset
}