Skip to content

Commit

Permalink
fix(x-web): 修复 dialogPage 获取 pageBody safeAreaInsets 异常问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenyuWang committed Jan 21, 2025
1 parent a7c3f3c commit 444a2e3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
31 changes: 16 additions & 15 deletions packages/uni-h5/dist-x/uni-h5.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -8212,11 +8212,13 @@ class UniPageImpl {
const currentPage = getCurrentPage();
let container = document;
if (isDialogPageImpl(this)) {
const dialogPages = currentPage.getDialogPages();
if (dialogPages.indexOf(this) === -1) {
throw new Error("Can't get pageBody of other dialog page");
const dialogPage = document.querySelector(
`uni-page[data-page="${(_a = this.vm) == null ? void 0 : _a.route}"]`
);
if (!dialogPage) {
throw new Error("dialogPage not found");
}
container = document.querySelector(`uni-page[data-page="${(_a = this.vm) == null ? void 0 : _a.route}"]`);
container = dialogPage;
} else if (this !== currentPage) {
throw new Error("Can't get pageBody of other page");
}
Expand All @@ -8235,24 +8237,23 @@ class UniPageImpl {
const currentPage = getCurrentPage();
let container = document;
if (isDialogPageImpl(this)) {
const dialogPages = currentPage.getDialogPages();
if (dialogPages.indexOf(this) === -1) {
throw new Error("Can't get safeAreaInsets of other dialog page");
const dialogPage = document.querySelector(
`uni-page[data-page="${(_a = this.vm) == null ? void 0 : _a.route}"]`
);
if (!dialogPage) {
throw new Error("dialogPage not found");
}
container = document.querySelector(`uni-page[data-page="${(_a = this.vm) == null ? void 0 : _a.route}"]`);
container = dialogPage;
} else if (this !== currentPage) {
throw new Error("Can't get safeAreaInsets of other page");
}
const pageWrapperEdge = getPageWrapperInfo(container);
const systemSafeAreaInsets = getSystemSafeAreaInsets();
const computeEdge = (bodyEdge, nativeEdge) => {
return Math.max(0, nativeEdge - bodyEdge);
};
return {
top: computeEdge(pageWrapperEdge.top, systemSafeAreaInsets.top),
left: computeEdge(pageWrapperEdge.left, systemSafeAreaInsets.left),
right: computeEdge(pageWrapperEdge.right, systemSafeAreaInsets.right),
bottom: computeEdge(pageWrapperEdge.bottom, systemSafeAreaInsets.bottom)
top: Math.max(pageWrapperEdge.top, systemSafeAreaInsets.top),
left: Math.max(pageWrapperEdge.left, systemSafeAreaInsets.left),
right: Math.max(pageWrapperEdge.right, systemSafeAreaInsets.right),
bottom: Math.max(pageWrapperEdge.bottom, systemSafeAreaInsets.bottom)
};
}
getPageStyle() {
Expand Down
24 changes: 12 additions & 12 deletions packages/uni-h5/src/x/framework/setup/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ class UniPageImpl implements UniPage {
const currentPage = getCurrentPage() as unknown as UniPage
let container: Document | Element = document
if (isDialogPageImpl(this)) {
const dialogPages = currentPage.getDialogPages()
if (dialogPages.indexOf(this) === -1) {
throw new Error("Can't get pageBody of other dialog page")
}
container = document.querySelector(
const dialogPage = document.querySelector(
`uni-page[data-page="${this.vm?.route}"]`
)!
)
if (!dialogPage) {
throw new Error('dialogPage not found')
}
container = dialogPage
} else if (this !== currentPage) {
throw new Error("Can't get pageBody of other page")
}
Expand All @@ -108,13 +108,13 @@ class UniPageImpl implements UniPage {
const currentPage = getCurrentPage() as unknown as UniPage
let container: Document | Element = document
if (isDialogPageImpl(this)) {
const dialogPages = currentPage.getDialogPages()
if (dialogPages.indexOf(this) === -1) {
throw new Error("Can't get safeAreaInsets of other dialog page")
}
container = document.querySelector(
const dialogPage = document.querySelector(
`uni-page[data-page="${this.vm?.route}"]`
)!
)
if (!dialogPage) {
throw new Error('dialogPage not found')
}
container = dialogPage
} else if (this !== currentPage) {
throw new Error("Can't get safeAreaInsets of other page")
}
Expand Down

0 comments on commit 444a2e3

Please sign in to comment.