Files
sundynix-pets/pets-fe/components/safe-top/index.js
T
Blizzard 46ac8f8a47
ci-cd / verify (push) Successful in 4s
ci-cd / deploy (push) Skipped
Respect mini program status bar and menu safe area
2026-10-04 09:53:07 +08:00

22 lines
595 B
JavaScript

function topHeight() {
const windowInfo = wx.getWindowInfo ? wx.getWindowInfo() : wx.getSystemInfoSync();
const statusHeight = windowInfo.statusBarHeight || 24;
let menuBottom = 0;
try {
const menu = wx.getMenuButtonBoundingClientRect();
menuBottom = menu && menu.bottom ? menu.bottom : 0;
} catch (_) {
// Some development environments do not expose the menu geometry.
}
return Math.ceil(Math.max(menuBottom, statusHeight + 44) + 12);
}
Component({
data: { height: 100 },
lifetimes: {
attached() {
this.setData({ height: topHeight() });
},
},
});