React Native VisionCamera
VisionCamera is a high-performance, feature-rich camera library for React Native, currently at version 5.0.1. It provides direct access to camera hardware, supporting advanced features like custom frame processing (via C++ JSI) and granular control over camera devices and capabilities. Version 5.0.0 marked a significant rewrite, building upon 'Nitro Modules' and introducing a new 'Constraints API' for more flexible camera configuration. The library maintains a regular release cadence, with frequent patch updates addressing bugs and minor features within major versions, and new major versions (like v5) introducing substantial architectural changes. Its key differentiators include superior performance, direct native control, and advanced customization options not typically found in simpler camera abstractions.
Common errors
-
Invariant Violation: 'RCTVisionCamera' could not be found. Are you sure 'react-native-vision-camera' is installed and linked correctly?
cause Native module not linked or found. Common after `npm install` without rebuilding native projects, or during React Native upgrades.fixRun `npx pod-install` in your iOS directory and rebuild your app for both platforms. Ensure `react-native-vision-camera` is properly added to `package.json` and `node_modules`. -
Error: Permission denied. Make sure to request Camera permission.
cause The application does not have the necessary camera permissions from the user or the `AndroidManifest.xml`/`Info.plist` entries are missing.fixUse `useCameraPermission()` hook to request permissions at runtime and ensure the correct permission declarations are present in `AndroidManifest.xml` (Android) and `Info.plist` (iOS). -
Undefined symbol: _OBJC_CLASS_$_VisionCameraView
cause iOS linker error, typically indicating that the VisionCamera framework is not correctly linked or embedded.fixEnsure `npx pod-install` has been run and Xcode project settings correctly link the `VisionCamera` framework. Clean Xcode build folder and rebuild. -
Could not find `react-native-nitro-modules` (or `react-native-nitro-image`) in `node_modules`.
cause VisionCamera v5.0.0+ has new peer dependencies that must be explicitly installed.fixInstall the required peer dependencies: `npm install react-native-nitro-modules react-native-nitro-image` and then run `npx pod-install` and rebuild your app.
Warnings
- breaking VisionCamera v5.0.0 is a complete rewrite based on 'Nitro Modules' and introduces a new 'Constraints API'. Migration from v4 will require significant code changes, including updating imports, camera configuration, and potentially adapting to new APIs for frame processing and other features. Ensure `react-native-nitro-modules` and `react-native-nitro-image` are installed.
- breaking The `videoBitRate` prop was moved from `startRecording({ ... })` options to a direct prop on the `<Camera />` component in v4.6.0. This change was made to enable Android support for `videoBitRate`.
- gotcha Camera permissions must be explicitly added to your application's `Info.plist` (iOS) and `AndroidManifest.xml` (Android) files. The library cannot function without these native manifest entries.
- gotcha Linking native modules properly is crucial. Issues often arise from incorrect `pod install` or Android project configuration after installing the package or upgrading React Native.
- gotcha Certain devices might not load camera devices correctly on app start, leading to a `No Camera Device Found` error or similar initialization exceptions.
Install
-
npm install react-native-vision-camera -
yarn add react-native-vision-camera -
pnpm add react-native-vision-camera
Imports
- Camera
const Camera = require('react-native-vision-camera')import { Camera } from 'react-native-vision-camera' - useCameraDevice
import { useCameraDevice } from 'react-native-vision-camera' - useCameraPermission
import { useCameraPermission } from 'react-native-vision-camera' - useFrameProcessor
import { useFrameProcessor } from 'react-native-vision-camera'
Quickstart
import React, { useEffect } from 'react';
import { View, Text, StyleSheet, Linking, Alert } from 'react-native';
import { Camera, useCameraDevice, useCameraPermission } from 'react-native-vision-camera';
const App = () => {
const { hasPermission, requestPermission } = useCameraPermission();
const device = useCameraDevice('back');
useEffect(() => {
if (!hasPermission) {
requestPermission().then(granted => {
if (!granted) {
Alert.alert(
'Permission Required',
'Camera access is required to use this feature. Please enable it in settings.',
[
{ text: 'Cancel', style: 'cancel' },
{ text: 'Open Settings', onPress: () => Linking.openSettings() }
]
);
}
});
}
}, [hasPermission, requestPermission]);
if (!hasPermission) {
return <Text style={styles.permissionText}>Requesting Camera Permission...</Text>;
}
if (device == null) {
return <Text style={styles.permissionText}>No Camera Device Found.</Text>;
}
return (
<View style={styles.container}>
<Camera
style={StyleSheet.absoluteFill}
device={device}
isActive={true}
photo={true} // Enable photo capture
video={true} // Enable video capture
// frameProcessor={frameProcessor} // Uncomment for custom frame processing
// frameProcessorFps={30} // Set frame processor FPS
/>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'black',
},
permissionText: {
flex: 1,
color: 'white',
textAlign: 'center',
textAlignVertical: 'center',
fontSize: 18,
},
});
export default App;