Command palette

@yasinsensoy/native

React Native · Components

SafeAreaProvider

Overrides safe area values for the subtree.

12 exports

Import

import {
  SafeAreaProvider,
  SafeAreaView,
  useSafeAreaInsets,
  estimateInsets,
  getSafeAreaInsets,
  subscribeSafeAreaInsets,
  hasNativeSafeArea,
} from "@yasinsensoy/native";

Overrides safe area values for the subtree. UIProvider places this itself (the safeAreaInsets prop); using it separately is only needed when a subtree needs different values (e.g. a non-fullscreen panel you draw yourself).

SafeAreaProvider({ children, insets }: SafeAreaProviderProps): JSX.Element

SafeAreaView

component

A view that applies the safe area as its own padding: content does not go under the notch, status bar or navigation bar. Values are live. Use it in views that touch the screen edge (values are relative to the window edges).

SafeAreaView({ ref, edges, mode, style, ...props }: SafeAreaViewProps): JSX.Element

Examples

<SafeAreaView edges={["top", "bottom"]} style={{ flex: 1, padding: 16 }}>
  <Screen />
</SafeAreaView>

Safe area insets. The component re-renders when the value changes (rotation, hiding the status/navigation bar, foldable screen, split screen). Works outside UIProvider too.

Values come from the library's own native module (react-native-safe-area-context is not required); if the module is not compiled (web, test) they are estimated.

useSafeAreaInsets(): EdgeInsets

Examples

const insets = useSafeAreaInsets();
<View style={{ paddingTop: insets.top, paddingBottom: insets.bottom }} />

Estimate of safe area insets when there is no native module (web, test, an app whose native code is not compiled). Status bar height on Android; notch / Dynamic Island values by device size on iOS.

estimateInsets(width: number, height: number): Insets

Current safe area insets (relative to the window edges, dp/pt). Real values when the native module exists (notch, Dynamic Island, status and navigation bars, display cutout), otherwise an estimate. Inside a component use useSafeAreaInsets; it re-renders when the value changes.

getSafeAreaInsets(): Insets

Registers a function called when the insets change (rotation, hiding the bars, foldable screen, split screen). Returns a function that unregisters it.

subscribeSafeAreaInsets(listener: () => void): () => void

Whether the native safe area module is compiled in this app. If false the values are estimates (see estimateInsets).

hasNativeSafeArea(): boolean

Edge insets (dp/pt): notch, status bar, navigation bar, display cutout.

type EdgeInsets = Insets

Edge

type

Screen edge.

type Edge = "top" | "right" | "bottom" | "left"

How an edge combines with the safe area:

  • "additive": the safe area is added to the padding in your style (default).
  • "maximum": the larger of your style padding and the safe area is used (on devices without a notch your own padding still remains).
  • "off": this edge is not applied.
type EdgeMode = "additive" | "maximum" | "off"

SafeAreaProvider props.

NameTypeDescription
children?ReactNodeContent.
insets?Partial<EdgeInsets> | undefinedManually given insets: given edges override native values (tests, screenshots, custom layouts). Edges not given stay live.

SafeAreaView props.

Extends: ViewProps

NameTypeDefaultDescription
ref?Ref<ViewRef>Ref of the underlying native view.
edges?readonly Edge[] | Partial<Record<Edge, EdgeMode>>all four edgesEdges to apply: a list (all "additive") or a per-edge mode. See EdgeMode.
mode?"padding" | "margin""padding"Whether the inset is inner (padding) or outer (margin).