# Screen (/docs/native/components/screen)

<Preview id="screen/inbox" title={null} />

## Installation [#installation]

<ComponentInstall name="screen" />

## Usage [#usage]

```tsx title="app/index.tsx"
import { Button } from "@/components/ui/button";
import { Screen } from "@/components/ui/screen";
import { Text } from "@/components/ui/text";
import { useRouter } from "expo-router";

export default function Example() {
  const router = useRouter();

  function save() {
    console.log("saved");
  }

  return (
    <Screen>
      <Screen.Navbar>
        <Screen.Navbar.BackButton onPress={router.back} />
        <Screen.Navbar.Title>Settings</Screen.Navbar.Title>
      </Screen.Navbar>

      <Screen.ScrollArea contentContainerClassName="gap-4 p-4">
        <Text.Header>Notifications</Text.Header>
        <Text.Paragraph>Choose which alerts reach this device.</Text.Paragraph>
      </Screen.ScrollArea>

      <Screen.Footer>
        <Button onPress={save}>Save</Button>
      </Screen.Footer>
    </Screen>
  );
}
```

The navbar and footer measure themselves into a Reanimated context and every scrollable reserves
exactly that, so no screen carries a hand-tuned padding number.

## Placement [#placement]

`overlay` floats the chrome over the content, which insets itself to match; `static` puts it in the
flow and paints an opaque surface.

```tsx
<Screen.Navbar placement="static">…</Screen.Navbar>
<Screen.Footer placement="overlay">…</Screen.Footer>
```

## Borders [#borders]

Both hairlines are drawn at rest; `fadeBorderOnScroll` opts into a scroll-linked ramp instead — the
navbar's brightens as you leave the top, the footer's fades out as the content runs out.

```tsx
<Screen.Navbar fadeBorderOnScroll>…</Screen.Navbar>
<Screen.Footer fadeBorderOnScroll>…</Screen.Footer>
```

## Chat lists [#chat-lists]

`Screen.ChatList` is a discriminated union on `variant`: `legend` takes chronological oldest-first
data and LegendList's own `renderItem`, `flat` is an inverted `FlatList` with newest-first data and
React Native's.

```tsx
<Screen.ChatList
  composerBaseHeight={56}
  data={messages}
  renderItem={renderMessage}
  variant="legend"
/>
```

<Callout type="warn" title="Seed a chat list with composerBaseHeight">
The footer publishes its real height a commit or two after the list's first layout, and the list has
already scrolled to the end by then. Without the seed the newest message hides under the
composer — intermittently, which is the worst kind of wrong.
</Callout>

## Loading and error [#loading-and-error]

Whole-screen states, each with its own navbar so a back gesture still works.

<Preview id="screen/loading-and-error" />

```tsx
<Screen.Loading title="Loading" />

<Screen.Error message="That project no longer exists." onBack={router.back} title="Not found">
  <Button onPress={retry}>Try again</Button>
</Screen.Error>
```

## API Reference [#api-reference]

### Requirements [#requirements]

<Callout type="warn">
The app must mount [`DelacourProvider`](/docs/native/components/provider) at its root. `Screen`
reads the safe-area and keyboard providers, and `<KeyboardStateSync />` is what keeps the keyboard's
shared values honest between screens — without it a screen renders "keyboard open" over a keyboard
that is not there.
</Callout>

`@legendapp/list` is an optional peer, so an app that never imports `Screen` never resolves it.

### Parts [#parts]

<Preview id="screen/a-pushed-screen" />

| Part | What it is |
| --- | --- |
| `Screen.Navbar` | Pinned top chrome. Compound: `.Title`, `.Subtitle`, `.BackButton` |
| `Screen.Content` | The content region between the chrome |
| `Screen.View` | A non-scrolling body |
| `Screen.Header` | A scrolling header inside the content region |
| `Screen.Footer` | Pinned bottom chrome, keyboard-aware |
| `Screen.ScrollArea` | A `ScrollView` with the reserves applied |
| `Screen.FlatList` / `.SectionList` / `.LegendList` | Virtualised lists, same reserves |
| `Screen.ChatList` | An inverted or oldest-first chat list |
| `Screen.Loading` / `Screen.Error` | Whole-screen states |

### Screen [#screen]

The root. It renders a `View` and passes `ViewProps` through.

<TypeTable
  type={{
    debug: {
      type: "boolean",
      description: "Paint the layout layers in debug colours — the footer's bands, a scrollable's spacers, a chat list's composer clearance. Deliberately not gated behind __DEV__: a reserve only goes wrong on a release build.",
    },
    className: { type: "string" },
    children: { type: "ReactNode" },
  }}
/>

### Shared shapes [#shared-shapes]

Three prop shapes are shared between parts rather than restated, which is why the tables below are
short.

<TypeTable
  type={{
    "ScreenInsetProps": {
      type: "ViewProps & { insets?: ScreenEdge[] }",
      description: "`Content` and `Header`. `insets` names the safe-area edges to pad against — none by default.",
    },
    "ScreenPlacementProps": {
      type: "ViewProps & { placement?: \"overlay\" | \"static\" }",
      description: "`Navbar` and `Footer`. `overlay` floats the part and the content insets itself by the measured height; `static` puts it in the flow.",
    },
    "ScreenScrollableProps": {
      type: "{ header?: ReactNode; className?: string; contentContainerClassName?: string }",
      description: "Every scrollable. `header` is separate from a list's own ListHeaderComponent so a caller can use both without interleaving them.",
    },
  }}
/>

### `Screen.Navbar` [#screennavbar]

Pinned chrome at the top. Publishes its measured height, which is what everything below it clears.

<TypeTable
  type={{
    placement: { type: '"overlay" | "static"', default: '"overlay"' },
    actions: { type: "ReactNode", description: "Trailing content, laid out against the far edge." },
    center: { type: "ReactNode", description: "Content centred independently of the leading and trailing regions." },
    fadeBorderOnScroll: { type: "boolean", description: "Fade the bottom border in as content scrolls under it." },
    backgroundClassName: { type: "string", description: "The navbar's own surface, behind its content." },
    className: { type: "string" },
    children: { type: "ReactNode" },
  }}
/>

### `Screen.Footer` [#screenfooter]

Pinned chrome at the bottom, and the part that rides the keyboard.

<TypeTable
  type={{
    placement: { type: '"overlay" | "static"', default: '"overlay"' },
    sticky: { type: "boolean", description: "Keep the footer against the keyboard as it opens, rather than behind it." },
    isFocused: { type: "boolean", description: "Whether a field inside the footer holds focus, which changes the clearance it asks for." },
    fadeBorderOnScroll: { type: "boolean" },
    className: { type: "string" },
    children: { type: "ReactNode" },
  }}
/>

### `Screen.Content` / `Screen.Header` / `Screen.View` [#screencontent--screenheader--screenview]

`Content` and `Header` take `ScreenInsetProps`; `View` is a plain `ViewProps` box that clears the
chrome without scrolling.

<TypeTable
  type={{
    insets: { type: '("top" | "right" | "bottom" | "left")[]', description: "`Content` and `Header` only." },
    textInputNativeID: { type: "string", description: "`Content` only. Ties the region to a field for keyboard avoidance." },
    className: { type: "string" },
    children: { type: "ReactNode" },
  }}
/>

### The scrollables [#the-scrollables]

`Screen.ScrollArea`, `Screen.FlatList`, `Screen.SectionList`, `Screen.LegendList` and
`Screen.ChatList` each extend their underlying list's own props plus `ScreenScrollableProps`. They
insert the navbar and footer spacers for you, so content clears the chrome without a manual
`contentContainerStyle`.

<TypeTable
  type={{
    header: { type: "ReactNode", description: "Above the content, below the navbar spacer." },
    keyboardAware: {
      type: "boolean",
      default: "false",
      description: "`ScrollArea` only. Scrolls the focused field clear of both the keyboard and a sticky footer.",
    },
    contentContainerClassName: { type: "string" },
    className: { type: "string" },
  }}
/>

### `Screen.Error` / `Screen.Loading` [#screenerror--screenloading]

Whole-screen states, each with its own navbar so a back gesture still works.

<TypeTable
  type={{
    title: { type: "string" },
    message: { type: "string", description: "`Error` only, and required — a state with nothing to say is not one." },
    onBack: { type: "() => void" },
    showNavbar: { type: "boolean", description: "Draw the navbar above the state." },
    children: { type: "ReactNode", description: "`Error` only — actions below the message." },
  }}
/>

### `Screen.NavbarBackButton` [#screennavbarbackbutton]

A `Pressable`, so the vocabulary is inherited. `onPress` is **required** — this library takes no
navigation dependency, so the app wires `router.back()` itself. There is no `Navbar.Action` either:
a navbar action is `<Button size="icon-sm" variant="secondary">`.

<TypeTable
  type={{
    onPress: { type: "() => void", description: "Required." },
    onBeforeBack: {
      type: "() => boolean",
      description: "Return false to cancel the navigation — an unsaved-changes guard.",
    },
    glyph: { type: "ScreenBackButtonGlyph", description: "Which chevron or arrow to draw." },
    className: { type: "string" },
  }}
/>

### `Screen.NavbarTitle` / `NavbarSubtitle` / `NavbarBackground` / `FooterBackground` [#screennavbartitle--navbarsubtitle--navbarbackground--footerbackground]

The two text parts are `Text` presets and take its props. The two background parts take `ViewProps`
and exist for a surface that has to sit behind the chrome rather than inside it — reach for
`backgroundClassName` on the navbar first.

<TypeTable type={{ className: { type: "string" }, children: { type: "ReactNode" } }} />
