UVC Camera for RN
npm install @prasiddha-n/react-native-uvc-cameraUVC camera component for React Native powered by UVCAndroid.
Android only.
``sh`
npm install @prasiddha-n/react-native-uvc-camera
`tsx
import React, { useEffect, useRef } from 'react';
import { SafeAreaView, StyleSheet } from 'react-native';
import { UVCCamera } from '@prasiddha-n/react-native-uvc-camera';
export function UvcScreen() {
const cameraRef = useRef
useEffect(() => {
cameraRef.current?.openCamera();
return () => cameraRef.current?.closeCamera();
}, []);
const capture = async () => {
const photo = await cameraRef.current?.takePhoto();
console.log(photo?.path);
};
return (
);
}
const styles = StyleSheet.create({
container: { flex: 1, backgroundColor: '#000' },
camera: { flex: 1 },
});
`
Add your own UI button to call capture() when you need a still image.
is a pure view that forwards all standard ViewProps. Every interaction happens through the ref.
| Method | What it does |
| --- | --- |
| openCamera() | Starts discovery, picks the preferred UVC device, and begins streaming to the surface. |closeCamera()
| | Stops the preview and releases the active USB camera. Call on unmount or app background. |takePhoto(): Promise
| | Captures a JPEG to the device temp dir and returns { path }. Add file:// when displaying the image. |updateAspectRatio(width, height)
| | Persists a preferred preview size. The closest matching mode is selected on the next openCamera(). |setCameraBright(value)
| | Forwards value to the UVC brightness control (library expects a 0–100 percentage). |setCameraContrast(value)
| | Sets UVC contrast (integer range depends on the camera; usually 0–255). |setCameraSaturation(value)
| | Adjusts saturation via the UVC control (device-specific range). |setCameraSharpness(value)
| | Updates sharpness (device-specific range). |setCameraZoom(value)
| | Sends a relative zoom value to the camera and toggles autofocus. Default is 500. |setDefaultCameraVendorId(vendorId)
| | Stores the USB vendor id to auto-select when multiple cameras are connected. Provide the decimal form (e.g. 0x0bda → 3034). |
All setters resolve immediately; they don’t reject even if the device silently ignores out-of-range values. Clamp inputs on the JS side if your hardware requires specific limits.
`ts`
await cameraRef.current?.updateAspectRatio(1920, 1080);
await cameraRef.current?.setCameraBright(70);
await cameraRef.current?.setCameraContrast(40);
await cameraRef.current?.setCameraSaturation(128);
await cameraRef.current?.setCameraSharpness(64);
await cameraRef.current?.setCameraZoom(600);
await cameraRef.current?.setDefaultCameraVendorId(3034);
`ts`
type PhotoFile = {
path: string; // temp file path, prepend file:// for
};
Remember that temp files may be deleted when the app closes—move them if you need persistence.
ProGuard users must manually add the below options.
```
-keep class com.herohan.uvcapp.* { ; }
-keep class com.serenegiant.usb.* { ; }
-keepclassmembers class implements com.serenegiant.usb.IButtonCallback {;}
-keepclassmembers class implements com.serenegiant.usb.IFrameCallback {;}
-keepclassmembers class implements com.serenegiant.usb.IStatusCallback {;}
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
---
Made with create-react-native-library