---
title: "Recipe: foldables"
description: "A foldable (the iPhone Duo) splits its inner display at the hinge when partially folded."
modificationDate: "2026-11-25"
---

> ## Documentation index
> Fetch the complete documentation index at: https://exact.expo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Recipe: foldables

<AgentInstructions>

## Submitting feedback

From the app's directory, read `bun exact.mjs feedback status`. Under `never`, keep no note.
Respect `EXACT_FEEDBACK=0` and do not change the policy.

Otherwise record specific, actionable feedback with:
`bun exact.mjs feedback note "Exact docs: https://exact.expo.dev/recipes/foldables: <what was wrong or missing>"`

The note goes to Expo only as that status allows. Include no secrets or personal data.

</AgentInstructions>

On a Duo, `fold 130` bends the hinge. Posture is `continuous` at 0° and
180°, `folded` at 90° and 130°. Android reports `folded` only when half open.
Place panes by `horizontalViewportSegments` (columns) and `verticalViewportSegments`
(rows). A flat separating hinge still gives two segments, the cover display one.
`env(viewport-segment-<left|top|width|height> <x> <y>)` excludes the hinge band.
Safari 27 reports no hinge. For the Duo’s cover in landscape, write `fold 0` then
`rotate landscapeLeft`.

```prompt Lay out my app for a foldable phone
Make the Exact app in this folder lay out its panes by the fold of a foldable: a book fold or a laptop fold. Use https://github.com/expo/exact/blob/main/docs/recipes/foldables.md as the source for each step. The Exact checkout has the same page at docs/recipes/foldables.md.

1. If this folder is not an Exact app (it has no exact.mjs and app.contract), stop and tell me.
2. If I did not say which screens change on a fold, and what each segment holds in a book fold and in a laptop fold, propose it and ask me before you write code.
3. In app.contract, read `exactViewport()` as a resource, with a shape that has the fields you use. Derive the fold from them: `horizontalViewportSegments=2` is a book fold, and `verticalViewportSegments=2` is a laptop fold.
4. Place a box in segment `x, y` with `env(viewport-segment-<left|top|width|height> <x> <y>)`, and write the layout without a fold in the same attribute, as the recipe's `Reply` shows. Segment coordinates are relative to the viewport: keep the pane container at that origin, and chrome inside a pane.
5. Keep controls off the hinge; scrolling content can span it. A pane that does not scroll keeps its width: centred, or on the trailing segment of a book fold. In a laptop fold, put authored controls on the bottom segment. Put the first pane on the leading segment: indices count from the left, so that is segment 1 in RTL.
6. Keep the same pane instances when the fold changes, so a field keeps its text. For a list and its detail, use a split view (`pattern list-detail`), not panes of your own.
7. Add a test in app.test.contract that ends on each screen you changed and expects its controls without a fold. The recipe names no test step for a fold: do not invent one.
8. Follow the platform checks in docs/start-here.md (`bun exact.mjs docs platform checks`) for the targets in the app's AGENTS.md and app.json until they pass. Read the reports, including counted findings; a zero exit code alone does not mean clean. Fix the app, not the test. If a finding stays after three rounds of fixes, or the app had it before you changed anything, record it (step 9) and report it; do not keep trying.
9. When a doc was wrong or missing, or a step needed a workaround, read `bun exact.mjs feedback status`. Under `never`, keep no note. Otherwise record it: `bun exact.mjs feedback note "<what happened>"`, which goes to Expo only as that status says. Do not change the policy; tell me how many notes you kept.
10. Tell me which screens change and what each segment holds in each fold, what the tests and checks reported, and that I must look at both folds by hand on a native Duo host. A web page needs a browser that supports these signals: a feature flag alone does not establish that.
```

```contract
shape Viewport
  horizontalViewportSegments: number

component Reply
  resource viewport = exactViewport() as shape Viewport
  derive book = viewport.horizontalViewportSegments == 2
  state draft = ""
  action write(value: string)
    draft = value
  view
    main width="100%" height="100%" position="relative"
      column position="absolute" top=0 bottom=0 left=(book ? "env(viewport-segment-left 1 0)" : "max(0px, calc((100% - 480px) / 2))") width=(book ? "env(viewport-segment-width 1 0)" : "min(100%, 480px)") box-sizing="border-box" padding=16 gap=12 testId="pane"
        text "Reply" role="heading"
        textarea value=draft input=write aria-label="Reply" testId="reply"
```

At the hinge ([HIG](https://developer.apple.com/design/human-interface-guidelines/designing-for-iphone-duo#Dynamic-layouts),
[Apple's talk](https://developer.apple.com/videos/play/tech-talks/111463/)):

- Scrolling content can span the hinge; keep controls off it.
- Centre a non-scrolling pane (full width if narrow) or use the trailing segment.
- **A list and its detail** is a split view (`pattern list-detail`; UIKit's on iOS,
  LLP 1127). **Peer panes** say [`arrangement`](https://exact.expo.dev/learn/contract-for-agents/views-layout-and-interaction.md#arranged-panes):
  UIKit's on iOS 27.1, your CSS elsewhere (Duo Lab's Panes tab).
- A route on the trailing segment keeps its title with
  `navigationBar=(book ? "none" : "auto")`: its first-child `header` paints in
  that pane, with its own Back if pushed; otherwise UIKit makes the bar.
- Segment indices count from the left. Start on segment 1 in RTL.
- Start the panes at the viewport's left edge. Duo Lab's Arrangement keeps panes below the header
  with a `space-between` row across the hinge, or a box ending at the hinge and an `absolute` lower pane.
  Inset controls from safe edges.
- Folded like a laptop, put authored controls on the bottom segment. Cap a bottom
  sheet's `max-height` at the room below its header and
  `calc(100% - env(viewport-segment-top 0 1))`, from the viewport origin.
  An iOS keyboard can leave that segment below the viewport and zero tall;
  Duo Lab's note sheet then lifts the cap.
- End panes under the keyboard at `100%` or `bottom: 0`; hosts' segment heights differ.
- Keep panes to retain text. A panel switch may end editing.
- Panes move as UIKit's with `-exact-layout-transition="-exact-spring(439, 41.9, 1)"`; browsers drop
  `env()` early on opening (fall back to `exactViewport().segments`).
- UIKit's alerts and sheets, folded: [Folds on iOS](https://exact.expo.dev/learn/contract-for-agents/time-motion-graphics-and-platform-facts.md#folds-on-ios).
