Skip to content

Commit ae8f213

Browse files
committed
feat(uni-app-x mp): UniPage支持pageBody、safeAreaInsets属性
1 parent 5f144c3 commit ae8f213

File tree

1 file changed

+26
-0
lines changed
  • packages/uni-mp-core/src/runtime

1 file changed

+26
-0
lines changed

Diff for: packages/uni-mp-core/src/runtime/page.ts

+26
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,32 @@ export function initPageInstance(mpPageInstance: MPComponentInstance) {
9797
get statusBarHeight(): number {
9898
return __GLOBAL__.getWindowInfo().statusBarHeight
9999
},
100+
get safeAreaInsets() {
101+
const windowInfo = __GLOBAL__.getWindowInfo()
102+
const screenBottom =
103+
windowInfo.screenHeight -
104+
windowInfo.screenTop -
105+
windowInfo.windowHeight
106+
const safeAreaBottom =
107+
windowInfo.screenHeight - windowInfo.safeArea.bottom
108+
return {
109+
top: Math.max(0, windowInfo.statusBarHeight - windowInfo.screenTop),
110+
left: 0,
111+
right: 0,
112+
bottom: Math.max(0, safeAreaBottom - screenBottom), // 无法计算,
113+
}
114+
},
115+
get pageBody() {
116+
const windowInfo = __GLOBAL__.getWindowInfo()
117+
return {
118+
top: windowInfo.screenTop,
119+
left: 0,
120+
right: windowInfo.windowWidth,
121+
bottom: windowInfo.windowHeight + windowInfo.screenTop,
122+
width: windowInfo.windowWidth,
123+
height: windowInfo.windowHeight,
124+
}
125+
},
100126
})
101127
}
102128
}

0 commit comments

Comments
 (0)