Lynx
useSafeArea
A hook that retrieves top/bottom safe area inset values in a Lynx app.
Available since@seed-design/lynx-react@0.1.0
Import
useSafeArea is included in the @seed-design/lynx-react package. It reads lynx.__globalProps.safeAreaInsetTop / safeAreaInsetBottom values injected by the host app first, and falls back to Lynx CSS env(safe-area-inset-*) if values are not available.
Usage
Basic Usage
Using with Box
Box pt="safeArea" / pb="safeArea" also internally use the same safe area resolution logic as useSafeArea.
How It Works
The value source priority is as follows.
lynx.__globalProps.safeAreaInsetTop/safeAreaInsetBottomenv(safe-area-inset-top)/env(safe-area-inset-bottom)
If the host injects a valid, non-0 numeric value, it is converted to a px string. If the value is missing or 0, a CSS env() string is returned, and the actual px resolution is left to the Lynx layout stage.
API
Return
| Property | Type | Description |
|---|---|---|
safeAreaInsetTop | string | The top safe area inset value. |
safeAreaInsetBottom | string | The bottom safe area inset value. |
Usage Notes
- If host global props are absent, a CSS
env(safe-area-inset-*)fallback is returned. This value is not resolved to px in JavaScript; it is resolved at the style/layout stage. - For cases like
BottomSheet.Content, where the component structure requires a safe area, the bottom safe area is handled inside the component. - v1 only supports top/bottom. left/right/p/px/py safe area shorthands are not exposed.
- In environments where native safe area calculation timing can be unstable, such as entry via a BG → FG deep link, verify that the host app reliably injects
lynx.__globalProps.safeAreaInsetTop/safeAreaInsetBottom.