-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip(uni-app-x web): 支持safeAreaInset css变量
- Loading branch information
Showing
3 changed files
with
86 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import safeAreaInsets from 'safe-area-insets' | ||
export function getPageWrapperInfo(pageBody?: HTMLElement) { | ||
const pageWrapper = | ||
pageBody || (document.querySelector('uni-page-wrapper') as HTMLElement) | ||
const pageWrapperRect = pageWrapper.getBoundingClientRect() | ||
|
||
const bodyRect = document.body.getBoundingClientRect() | ||
return { | ||
top: pageWrapperRect.top, | ||
left: pageWrapperRect.left, | ||
right: bodyRect.right - pageWrapperRect.right, | ||
bottom: bodyRect.bottom - pageWrapperRect.bottom, | ||
width: pageWrapperRect.width, | ||
height: pageWrapperRect.height, | ||
} | ||
} | ||
|
||
export const getSystemSafeAreaInsets = function () { | ||
return { | ||
top: safeAreaInsets.top, | ||
right: safeAreaInsets.right, | ||
bottom: safeAreaInsets.bottom, | ||
left: safeAreaInsets.left, | ||
} | ||
} | ||
|
||
/** | ||
* 注意web端页面安全区域较为特殊,如下四个值主要为满足fixed定位时能避开系统安全区域及页面top-window、left-window、nav-bar、tab-bar等的边界 | ||
*/ | ||
export function getSafeAreaInsets(pageBody?: HTMLElement) { | ||
const pageWrapperEdge = getPageWrapperInfo(pageBody) | ||
const systemSafeAreaInsets = getSystemSafeAreaInsets() | ||
return { | ||
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), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters