Skip to content

Camera

@symbiote-native/camera wraps expo-camera, so every SymbioteNative adapter can show a camera, not just React.

Terminal window
npm install @symbiote-native/camera

Scaffolding or extending a SymbioteNative app? npx @symbiote-native/cli new --camera (or add --camera in an existing app) installs and wires this for you.

Ask for permission first and render the view only once it is granted. Keep the handle of the view to take pictures, and wait for onCameraReady before you do.

import { useRef } from 'react';
import { CameraView, useCameraPermissions, type ICameraViewHandle } from '@symbiote-native/camera/react';
const [permission, requestPermission] = useCameraPermissions();
const camera = useRef<ICameraViewHandle>(null);
return permission?.granted === true ? (
<>
<CameraView ref={camera} style={{ flex: 1 }} facing="back" />
<button title="Take picture" onPress={() => camera.current?.takePictureAsync({ quality: 0.8 })} />
</>
) : (
<button title="Allow the camera" onPress={() => requestPermission()} />
);
Adapter How
React ref gets an ICameraViewHandle
Solid ref={handle => ...} gets the handle
Vue a template ref, the functions are exposed
Svelte bind:this, the component exports the functions
Angular @ViewChild(CameraView), the functions are members
Function Description
isCameraAvailableAsync() Whether the device has a camera, upstream’s CameraView.isAvailableAsync
getAvailableVideoCodecsAsync() iOS only
launchScanner(options?) / dismissScanner() The system scanner, iOS 16+ and Google’s code scanner
onModernBarcodeScanned(listener) Returns a subscription
isModernBarcodeScannerAvailable() Whether the device has the system scanner
scanFromURLAsync(url, types?) Scans an image, QR only on iOS
Camera.getCameraPermissionsAsync() and the three twins The permission calls the hooks use

useCameraPermissions and useMicrophonePermissions are hooks in React, Vue, Svelte and Solid and CameraPermissionsService and MicrophonePermissionsService in Angular.

  • The postinstall asks for both permissions. It writes NSCameraUsageDescription and NSMicrophoneUsageDescription into Info.plist and CAMERA and RECORD_AUDIO into the Android manifest. iOS needs the microphone text even if you only take pictures, because the same view can record. Reword both texts to fit your app.
  • Ask first, then render. Show CameraView only once useCameraPermissions reports granted.
  • onBarcodeScanned turns scanning on. The scanner is enabled exactly when you pass the prop, and barcodeScannerSettings={{ barcodeTypes: [...] }} narrows what it looks for.
  • CameraView takes no children. The native view does not host them, so draw controls and frames as siblings, absolutely positioned over it.
  • The handle works after onCameraReady. takePictureAsync and recordAsync before that can fail or return nothing.
  • active={false} stops the camera session without unmounting the view. iOS only, it is on by default.

The app crashes on iOS the first time the camera opens. A missing usage description kills the app. The postinstall writes both NSCameraUsageDescription and NSMicrophoneUsageDescription. If you removed one, put it back: iOS checks the microphone text for the camera view too.

The preview is a black box. Check that permission is granted before you render the view, that you are on a device (the iOS Simulator has no camera, test with isCameraAvailableAsync()), and wait for onCameraReady before you call the handle. A black preview with facing="front" on a development build was reported for one iOS release range, so also try the other facing to tell a configuration problem from a device problem.

The barcode callback fires many times, or only once. onBarcodeScanned is called for every detection, throttled per view. To scan once, stop passing it after the first result, for example onBarcodeScanned={isScanned ? undefined : handleScan}, which also switches the scanner off. If it fires only once on Android, that was reported as an Android regression and is closed upstream, so update the package. Limit the work with barcodeScannerSettings={{ barcodeTypes: ['qr'] }}.

I put children inside CameraView and got a warning or a crash. Upstream documents that the view does not support children. Render the overlay as a sibling above it: a parent View, the CameraView filling it, and your controls absolutely positioned on top.

Showing and hiding the camera freezes or crashes iOS. Mounting and unmounting CameraView over and over, or rendering it conditionally while it is starting, was reported to freeze the iOS Simulator and crash some builds. On iOS keep the view mounted and use active to stop the session instead of unmounting.

The torch turns off right after it switches on. enableTorch set at the same moment the view starts was reported to stay on for a fraction of a second on iOS. Set it after onCameraReady.

What is the system scanner? launchScanner() opens the platform’s own code scanner, iOS 16 and later and Google’s code scanner on Android. isModernBarcodeScannerAvailable() tells you whether the device has it, and onModernBarcodeScanned delivers the results.

Can I use it with a gesture library on the same screen? Long-press and pan handlers around a camera view were reported not to reach the gesture library on iOS from SDK 51 on. Put the gesture area on its own transparent view above the camera and not on the camera itself.

Sources:

expo-camera’s JS is hand-ported into this package’s core/. createCameraView(getNode) holds everything that belongs to one mounted view: the render, the handle with all the view functions and the barcode throttle. The friendly props are turned into the native ones in ensureNativeProps, which is where onBarcodeScanned becomes barcodeScannerEnabled. The statics of upstream’s class are plain functions of the package, and createHostNodeHolder (components) is how React, Vue and Solid reach the host node, NativeViewBase.hostNode() how Angular does. The native code is never vendored: expo-modules-autolinking resolves it from node_modules (see the native setup guide).