For the complete documentation index, see llms.txt. This page is also available as Markdown.

安全区域

在移动浏览器中,内容有时会因为状态栏或主页指示器等系统 UI 而被遮挡。Apps in Toss SDK 为了防止这种情况,提供了一个以像素为单位计算屏幕安全区域(Safe Area)间距值的函数。

尤其是在 iPhone X 及以上设备或部分 Android 设备上,使用全屏的网页应用时,系统 UI 经常会遮挡内容。使用下面的函数,就能轻松调整间距,让内容安全显示。

useSafeAreaInsets

为了防止在移动浏览器中内容被状态栏或主页指示器等系统 UI 遮挡的问题,它会以像素单位计算屏幕安全区域(Safe Area)的间距值。 useSafeAreaInsets 可在使用 ReactNative 开发时使用。

import { useSafeAreaInsets } from '@granite-js/native/react-native-safe-area-context';
const { top: safeAreaTop, right: safeAreaRight } = useSafeAreaInsets();
// 导航栏顶部间距:safeAreaTop
// 导航栏右侧间距:safeAreaRight + 10

最后更新于

这有帮助吗?