---
title: "Recipe: native views"
description: "A view needing a platform API (a map, the camera) is a Swift view: a hyphenated tag in app.json modules, made by modules/apple/.swift."
modificationDate: "2026-11-26"
---

> ## 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: native views

<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/native-views: <what was wrong or missing>"`

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

</AgentInstructions>

Use `exact-camera` from `@exact/camera`. See [calibration](https://exact.expo.dev/recipes/camera-calibration.md).

Declare a hyphenated tag in `app.json` under `modules`. Implement it with public APIs in `modules/apple/*.swift`.

```prompt Add a native view in Swift
Put a native Swift view (a map, the camera) in the Exact app in this folder. Use https://github.com/expo/exact/blob/main/docs/recipes/native-views.md as the source for each step. The Exact checkout has the same page at docs/recipes/native-views.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 view and which platform API it uses, ask me before you write code. If it is a video, use the `video` element with a `poster`, and write no Swift. If it is a Skia or Reanimated screen, build it from boxes, SVG and keyframes, and write no Swift.
3. Name the view with a hyphenated tag in `app.json` `modules`, and make it in `modules/apple/<name>.swift`: an `ExactModule` whose `views` names an `ExactNativeFactory`, and an `ExactNativeInstance` per view, as the recipe shows.
4. Follow the recipe's rules: props are strings and come all together on each change; send events with `events.message`, `press()`, `change(v)` or `load()`; give a natural size with `intrinsicSize`; take time only from `context.frames` and `context.after(ms)`, never a `CADisplayLink` or a timer. Make the view accessible as `bun exact.mjs docs native views accessibility` says.
5. In app.contract, place the view by its tag with an `aria-label`, and handle its events in actions. If app.ts reads data from the module, write no bake code: the resource shows its `else` row until launch.
6. Run `bun exact.mjs ios` to build the Swift, then `bun exact.mjs verify ios` until it passes. 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 7) and report it; do not keep trying.
7. 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.
8. Tell me the tag and what the view does, what the tests and verify reported, and how to drive it by hand: `bun exact.mjs agent ios --touch platform` for its touches, and `bun exact.mjs agent ios logs` for the newest crash report.
```

```text
component Clip
  state last = ""
  action seeked(at: string)
    last = at
  view
    column
      video-view source="intro.mp4" message=seeked aria-label="Intro" height=180
      text last testId="last"
```

```swift
import UIKit // AppKit under #if os(macOS)

final class Clip: ExactModule {
    override class var views: [String: ExactNativeFactory] {
        ["video-view": ExactNativeFactory(for: Clip.self) { clip, props, events in Video(clip, props, events) }]
    }
}
let exactModule: ExactModule.Type = Clip.self

final class Video: ExactNativeInstance {
    private let strip = VideoView() // an AVPlayerLayer and a tap recognizer
    private let pad: Clip
    private var ticket: ExactTicket?
    init(_ pad: Clip, _ props: [String: String], _ events: ExactNativeEvents) {
        self.pad = pad
        super.init(events: events)
        try? setProps(props)
        strip.tapped = { [weak self] at in events.message(String(at)); self?.start() }
        events.intrinsicSize(CGSize(width: 320, height: 180))
    }
    // A live ticket costs CPU.
    func start() {
        guard ticket == nil else { return }
        ticket = pad.context.frames { [weak self] f in
            guard let self, !self.strip.advance(to: f.now) else { return }
            self.ticket?.stop(); self.ticket = nil
        }
    }
    override var view: ExactNativeView { strip }
    override func setProps(_ props: [String: String]) throws { strip.src = props["source"] ?? "" }
    override func destroy() { ticket?.stop() }
}
```

- **Props are strings**, sent whole on change. Contract names (`value`, `src`) and events are reserved.
- **Web:** `modules/web/index.js` exports `abi = 1`, `roster`, `create(tag, el, propsJson, event, reply)`,
  `setProps(handle, propsJson)`, and `destroy(handle)`.
- **Events:** `events.message(text)` runs `message=`; `press()`, `change(v)`, `load()` likewise.
- **Time:** use `context.frames` / `context.after(ms)`, never `CADisplayLink` or timers, so `clock +N` advances it.
- **Touches:** add recognizers to the view; points `point(inside:)` declines fall through unless `press=` is set. Drive with `agent ios --touch platform`.
- **Delegates:** `ExactNativeInstance` is not an `NSObject`; hold an `NSObject` delegate.
- **Size:** CSS reads `events.intrinsicSize` on auto axes; Android calls [wrapContent()](https://github.com/expo/exact/blob/41ded8c5ede0b2959ef0daa83b1ff78545dd4428/host/android/README.md#compose-module-views).
- **Accessibility:** [native views](https://exact.expo.dev/learn/contract-for-agents/views-layout-and-interaction.md#native-views-accessibility).
- **Data:** `app.ts` calls `native!.watch('state'); return native!.call({op: 'state'});`; the `else` row shows until launch.
- **Crashes:** `agent ios logs`.
- **First frame:** views attach after first paint. Only cheap views set `ExactNativeFactory(firstFrame: true)` (runs on main at launch; defer `AVAudioEngine`).
