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

import { useSafeArea } from "@seed-design/lynx-react";

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

import { useSafeArea } from "@seed-design/lynx-react";

function Screen() {
  const { safeAreaInsetTop, safeAreaInsetBottom } = useSafeArea();

  return (
    <view
      style={{
        paddingTop: `calc(16px + ${safeAreaInsetTop})`,
        paddingBottom: safeAreaInsetBottom,
      }}
    >
      <text>Content</text>
    </view>
  );
}

Using with Box

import { Box } from "@seed-design/lynx-react";

function Screen() {
  return (
    <Box pt="safeArea" pb="safeArea">
      <text>Content</text>
    </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.

  1. lynx.__globalProps.safeAreaInsetTop / safeAreaInsetBottom
  2. env(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

PropertyTypeDescription
safeAreaInsetTopstringThe top safe area inset value.
safeAreaInsetBottomstringThe 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.

Table of contents