Skip to content

callstackincubator/apex-software-factory / .agents/skills/react-native-vision-camera

react-native-vision-camera

Unverified

Best-practices guide for React Native VisionCamera v5 setup, migration, capture, controls, outputs, and basic frame processing. Use the separate react-native-vision-camera-realtime skill for production low-latency GPU, ML, CV, Skia or WebGPU pipelines and frame-coupled overlays.

references/quickstart-v5.md

View on GitHub
# Quickstart — VisionCamera v5

Minimum working Camera on iOS and Android with v5.

## 1. Install

Core + required Nitro peers:

```sh
npm i react-native-vision-camera@5 react-native-nitro-modules react-native-nitro-image
cd ios && pod install
```

Optional, install only what the app needs:

```sh
# Frame Processors (worklets). The new default worklets engine is Software Mansion's
# react-native-worklets, NOT react-native-worklets-core.
npm i react-native-vision-camera-worklets react-native-worklets

# Barcode/QR (MLKit on iOS + Android, consistent formats)
npm i react-native-vision-camera-barcode-scanner

# GPU-accelerated frame resize for ML pipelines (Metal on iOS, Vulkan on Android)
npm i react-native-vision-camera-resizer

# GPS/EXIF metadata
npm i react-native-vision-camera-location

# Skia-based preview + shader effects.
npm i react-native-vision-camera-skia @shopify/react-native-skia react-native-vision-camera-worklets react-native-worklets
```

babel plugin is needed for worklet. `react-native-worklets/plugin` must be added in `babel.config.js` . See https://docs.swmansion.com/react-native-worklets/docs/

## 2. Permissions

**iOS — `ios/<App>/Info.plist`:**

```xml
<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) needs access to your Camera to capture photos and videos.</string>
<key>NSMicrophoneUsageDescription</key>
<string>$(PRODUCT_NAME) needs access to your Microphone to record audio.</string>
```

Add `NSLocationWhenInUseUsageDescription` only if using `react-native-vision-camera-location`.

**Android — `android/app/src/main/AndroidManifest.xml`:**

```xml
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
```

Request permissions in JS before rendering:

```tsx
import { useCameraPermission, useMicrophonePermission } from "react-native-vision-camera";

const { hasPermission, requestPermission } = useCameraPermission();
useEffect(() => {
  if (!hasPermission) requestPermission();
}, [hasPermission]);
```

## 3. First Camera — photo capture

The idiomatic v5 screen: hook-based permission → hook-based device → output(s) → `<Camera />`.

```tsx
import { useEffect } from "react";
import { StyleSheet } from "react-native";
import { useIsFocused } from "@react-navigation/native";
import {
  Camera,
  useCameraDevice,
  useCameraPermission,
  usePhotoOutput,
} from "react-native-vision-camera";

export function CameraScreen() {
  const { hasPermission, requestPermission } = useCameraPermission();
  useEffect(() => {
    if (!hasPermission) requestPermission();
  }, [hasPermission, requestPermission]);

  const device = useCameraDevice("back");
  const isFocused = useIsFocused();
  const photoOutput = usePhotoOutput();

  if (!hasPermission || device == null) return null;

  const onShutter = async () => {
    const photo = await photoOutput.capturePhoto({ flashMode: "auto" }, {});
    // Display in-memory without hitting disk:
    const image = await photo.toImageAsync(); // from react-native-nitro-image
    // ... render <Image source={image} />
  };

  return (
    <Camera
      style={StyleSheet.absoluteFill}
      device={device}
      isActive={isFocused}
      outputs={[photoOutput]}
    />
  );
}
```

Key differences from v4 in this snippet:

- `outputs={[photoOutput]}` replaces the `photo={true}` boolean prop.
- `capturePhoto` lives on the output, not the Camera ref.
- The return value is a `Photo` — in memory, with EXIF and camera calibration already attached. Use `capturePhotoToFile` only if you genuinely need a file path.
- `isActive={isFocused}` keeps the session configured but stopped when the screen is off-stage. Do not unmount the Camera to hide it.

## 4. Video recording — minimum

```tsx
import {
  Camera,
  useCameraDevice,
  useVideoOutput,
  usePhotoOutput,
} from "react-native-vision-camera";

const device = useCameraDevice("back");
const videoOutput = useVideoOutput({ enableAudio: true });
const photoOutput = usePhotoOutput();

const record = async () => {
  const recorder = await videoOutput.createRecorder({});
  await recorder.startRecording(
    (filePath, reason) => console.log("finished:", filePath, reason),
    (err) => console.error(err),
  );
  // later...
  await recorder.stopRecording();
};

return (
  <Camera
    style={StyleSheet.absoluteFill}
    device={device}
    isActive={true}
    outputs={[photoOutput, videoOutput]}
  />
);
```

Notes:

- A `Recorder` is **single-use**. Call `createRecorder` again for each recording.
- Audio is **off by default** — pass `enableAudio: true` and ensure microphone permission.
- `stopRecording()` resolves immediately; the `onFinished` callback fires once the file has been flushed.

## 5. Minimum Frame Processor

```tsx
import { Camera, useFrameOutput, useCameraDevice } from "react-native-vision-camera";

const device = useCameraDevice("back");
const frameOutput = useFrameOutput({
  pixelFormat: "yuv", // optional; default is 'native' (zero-copy). 'yuv' = CPU-accessible YUV (good for MLKit/OpenCV) — source: useFrameOutput.ts:123
  onFrame(frame) {
    "worklet";
    try {
      // ... work with frame.width, frame.height, frame.pixelFormat, native buffer
    } finally {
      frame.dispose(); // REQUIRED — buffer pool is bounded
    }
  },
});

return (
  <Camera style={StyleSheet.absoluteFill} device={device} isActive={true} outputs={[frameOutput]} />
);
```

Requires `react-native-vision-camera-worklets` + `react-native-worklets`. See [frame-processors.md](frame-processors.md) for async offloading, native plugin authoring, and pixel-format decisions.

## 6. Common gotchas on first install

- "Nitro module not found" / immediate native crash → peers missing. Install `react-native-nitro-modules` and `react-native-nitro-image`; for frame processors add `react-native-worklets` + `react-native-vision-camera-worklets`; run `pod install`.
- Frame processor silently does nothing → check both worklets packages are installed. v5 does not fall back to `worklets-core`.
- Camera is black on Android emulator → emulators rarely emulate all formats; test on a real device before debugging constraints.
- Immediate dealloc / crash when navigating away → you're unmounting the Camera. Mount it once and toggle `isActive`.
- Trying to set `format={...}` → that prop was removed. Use `constraints={[...]}`.

## Pointers

- Docs — Getting Started: https://visioncamera.margelo.com/docs
- Docs — Camera Outputs: https://visioncamera.margelo.com/docs/camera-outputs
- Worklets (Software Mansion): https://docs.swmansion.com/react-native-worklets/docs/
- Repo: https://github.com/mrousavy/react-native-vision-camera
- llms index: https://visioncamera.margelo.com/llms.txt / https://visioncamera.margelo.com/llms-full.txt
- Related: [migration-v4-to-v5.md](./migration-v4-to-v5.md), [outputs-and-constraints.md](./outputs-and-constraints.md), [frame-processors.md](./frame-processors.md), [capture-and-controls.md](./capture-and-controls.md)
writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deploymentStars: 321kUpdated Claude CodeCodexVerifiedInstall
xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved.Stars: 197kUpdated Claude CodeCodexVerifiedInstall
shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release.Stars: 118kUpdated Claude CodeCodexVerifiedInstall