Camera
ImagePicker.capture() (see Image picker) opens the system camera
over your app. For a camera inside your own screen - a scanner, a custom shutter - register the
<expo-camera> view and import the Camera directive, which applies to every <expo-camera> in
the template.
import { Camera } from '@ng-native/expo';
<expo-camera> once Camera is in the component's importsPlatforms. Available on macOS, Linux (through the Camera portal and PipeWire), iPadOS, iPhone and Android. Absent on Web host.
Install
npx expo install expo-cameraimport { Camera, cameraPermission, microphonePermission } from '@ng-native/expo/camera';The smallest thing that works
import { Component, viewChild } from '@angular/core';
import { Pressable, Text } from '@ng-native/components';
import { registerExpoViews } from '@ng-native/expo';
import { Camera, cameraPermission } from '@ng-native/expo/camera';
registerExpoViews('expo-camera'); // once, before the app mounts
@Component({
selector: 'app-shutter',
imports: [Camera, Pressable, Text],
template: `
@if (permission.granted()) {
<expo-camera facing="back" class="flex-1" />
<pressable (press)="shoot()"><text>Take picture</text></pressable>
} @else if (permission.blocked()) {
<text>Enable camera access in Settings to take a picture.</text>
} @else {
<pressable (press)="permission.ensure()"><text>Allow camera access</text></pressable>
}
`,
})
export class Shutter {
private readonly camera = viewChild(Camera);
protected readonly permission = cameraPermission();
protected async shoot(): Promise<void> {
const picture = await this.camera()?.takePicture({ quality: 0.8 });
if (picture) console.log(picture.uri, picture.width, picture.height);
}
}The camera renders only once permission.granted() is true, and shoot() is only reachable from
that branch. permission.blocked() is the state where the platform will not show its own dialog
again - ensure() would resolve to the same refusal without asking - so that branch sends the
user to Settings instead of retrying.
Registering the view
<expo-camera> is not registered by default. Call registerExpoViews('expo-camera') once at
startup, before the first commit that uses the element - it teaches the engine the Fabric
component name for expo-camera's view. expo-camera registers as the module's default view
(the Fabric name is ViewManagerAdapter_ExpoCamera, with no view name suffix), because the camera
is the only view the module renders.
View props
Camera's inputs are expo-camera's view props, typed from its own CameraViewProps, so a
template that imports Camera is checked against them: facing, flash, zoom, mode, mute,
mirror, autofocus, active, videoQuality, videoBitrate, animateShutter, pictureSize,
selectedLens, enableTorch, videoStabilizationMode, barcodeScannerSettings,
responsiveOrientationWhenOrientationLocked and ratio. flash and autofocus are committed as
flashMode and autoFocus, the names the native view reads, as expo-camera's CameraView
renames them. Those two names work as inputs too, and flash or autofocus wins when both are
set. barcodeScannerEnabled is the native prop CameraView sets when it is given
onBarcodeScanned: set it to scan, and (barcodeScanned) has each barcode.
<expo-camera facing="front" flash="auto" zoom="0.2" enableTorch mirror class="flex-1" />A boolean prop works bound, [enableTorch]="torch()", or written bare, enableTorch: the bare
attribute is true, and null or undefined leaves the prop to expo-camera's default. An input
left unset commits nothing, so the native view keeps its own default, but for flash, which is
off unless set, as expo-camera's CameraView sends it: the iOS view's own default is auto.
The camera permission
The view needs the camera permission before it shows anything. Nothing in Camera asks for it -
the directive takes pictures and passes the view its props - so ask yourself, with
cameraPermission(). It returns a Permission: status(),
granted() and blocked() as signals, and check(), request() and ensure() to read or ask.
protected readonly permission = cameraPermission();Made in an injection context, as a field of a component or a service, it checks a refusal again
each time the app comes back to the front, so turning the camera on in Settings shows the camera
without a restart. On iOS and Android it calls expo-camera's own permission functions, and on
macOS and Linux the desktop host's, so the same code runs on each. Where there is no such module,
as on the web or in a test in Node, it answers denied, and blocked() is true.
Add to Info.plist:
<key>NSCameraUsageDescription</key>
<string>Allow this app to access your camera</string>
<key>NSMicrophoneUsageDescription</key>
<string>Allow this app to access your microphone</string>The CAMERA (and, for video with audio, RECORD_AUDIO) Android permissions are added
automatically by the module's config plugin.
Taking a picture
takePicture(options) takes expo-camera's own CameraPictureOptions (minus
onPictureSaved and pictureRef, which do not apply here) and resolves to a
CameraCapturedPicture - uri, width, height, and base64 or exif if asked for. It
resolves to null before the view has reached the screen, or without the module. The picture is
a JPEG at quality, or a PNG with imageType: 'png', which ignores quality; on iOS and macOS
any other imageType rejects.
In React, takePictureAsync is a method on the camera component's ref. Underneath, it is one of
the functions Expo defines on the view itself (AsyncFunction('takePicture') in the native
module), which native finds by reading the tag off whatever it is called on. Camera calls that
same function with the tag the engine committed the view under, so no ref is needed - takePicture
is a method on the directive instance a viewChild reaches.
Recording a video
record(options) records from the same view and resolves once the recording stops - when
stopRecording() is called, when maxDuration (seconds) or maxFileSize (bytes) is reached,
or when the preview stops - to { uri }, a file in the cache directory. It takes expo-camera's
own CameraRecordingOptions (minus mirror, which expo-camera has deprecated for the view's
mirror prop), and resolves to null before the view has reached the screen, or without the
module.
<expo-camera mode="video" facing="back" class="flex-1" />protected readonly recording = signal(false);
protected async toggle(): Promise<void> {
if (this.recording()) {
await this.camera()?.stopRecording();
return;
}
this.recording.set(true);
try {
const video = await this.camera()?.record({ maxDuration: 60 }); // resolves when it stops
if (video) console.log(video.uri);
} finally {
this.recording.set(false);
}
}The view records with mode="video". Without mute on the view, record() needs the microphone
permission, microphonePermission(), a Permission like the camera's: without it, Android
rejects, and iOS and macOS record without sound. With mute, it records without sound and needs no
microphone permission. mute is an input of Camera, so the component imports Camera for it:
<expo-camera mode="video" mute /> and [mute]="muted()" both work, and null or undefined is
the default, with sound. record() takes no mute of its own. On macOS, the view's mute as
record() starts holds for the whole recording.
protected readonly microphone = microphonePermission();
protected async start(): Promise<void> {
// A refusal records without sound on iOS and macOS, and makes record() reject on Android.
await this.microphone.ensure();
try {
const video = await this.camera()?.record({ maxDuration: 60 });
if (video) console.log(video.uri);
} catch (error) {
console.warn('Not recorded', error);
}
}On macOS the microphone permission is the one audioRecorder needs too, so
microphonePermission() and recordingPermission() from @ng-native/expo/audio answer the same.
On macOS the movie is a QuickTime file (.mov) from the Mac's camera, with any mode. It has sound
only with the microphone already allowed, and record() never asks for it, so it records without
sound otherwise, as iOS does: ask with microphonePermission() first. One recording runs at a time
for a view; a second record() rejects until the first stops.
On Linux the camera comes through the Camera portal, which asks for access once and keeps the
answer, and its frames through PipeWire, with GStreamer's PipeWire plugin installed. facing and
mirror do nothing, since the portal offers the cameras as one. A picture is a JPEG or PNG of the
newest frame. The movie is a QuickTime file, H.264 where an x264 or OpenH264 encoder and h264parse
are installed and Motion JPEG otherwise. It has sound where an AAC encoder is installed and a
microphone is present: PipeWire records silence with no error when there is none, so with no
microphone it records without sound. Linux has no microphone permission, so microphonePermission()
reads as granted.
Reference
expo-cameradirective@ng-native/expoimport { Camera } from '@ng-native/expo';and add Camera to the component's importsInputs
facingCameraViewProps['facing']back unless set.
flashCameraViewProps['flash'] The flash for a picture. Committed as flashMode , the prop native reads, and as off unless set, as expo-camera 's CameraView sends it: iOS's own default is auto .
flashModeCameraViewProps['flash'] The native view's own name for flash , which flash wins over.
zoomnumberFrom 0, not zoomed, to 1, the device's furthest.
modeCameraViewProps['mode']picture unless set; video to record() .
muteboolean Record without sound, and without the microphone permission. A bare mute attribute is true, and unset ( undefined or null ) is expo-camera's default, with sound.
mirrorbooleanMirrors what the front camera takes. A bare attribute is true.
autofocusCameraViewProps['autofocus'] Committed as autoFocus , the prop native reads.
autoFocusCameraViewProps['autofocus'] The native view's own name for autofocus , which autofocus wins over.
activebooleanRuns the camera session. True unless set; false stops it with the view still there. iOS only.
videoQualityCameraViewProps['videoQuality']videoBitratenumber Bits per second. iOS needs a codec in record() 's options for it.
animateShutterbooleanPlays the shutter animation as a picture is taken. True unless set.
pictureSizestring One of the sizes expo-camera 's getAvailablePictureSizesAsync lists.
selectedLensstring A lens's deviceType , as expo-camera 's getAvailableLensesAsync lists them. iOS only.
enableTorchbooleanTurns the torch on. A bare attribute is true.
videoStabilizationModeCameraViewProps['videoStabilizationMode']barcodeScannerEnabledboolean Scans for barcodes, sending barcodeScanned . expo-camera 's React component sets this native prop when onBarcodeScanned is given; here it is set with the binding. A bare attribute is true.
barcodeScannerSettingsCameraViewProps['barcodeScannerSettings']responsiveOrientationWhenOrientationLockedbooleanTakes landscape pictures with the device turned, with the app locked upright. iOS only.
ratioCameraViewProps['ratio']The preview's aspect ratio. Android only.
Outputs
cameraReadyNativeSyntheticEvent<Record<string, never>>The preview has started.
mountErrorNativeSyntheticEvent<import('expo-camera').CameraMountError> The preview could not start, with expo-camera 's message.
barcodeScannedNativeSyntheticEvent<import('expo-camera').BarcodeScanningResult> A barcode was scanned, with barcodeScannerEnabled on.
Methods
takePicture(options: PictureOptions = {}): Promise<CameraPicture | null>Take a picture. Null without the module, or before the view has reached the screen - there is no camera to take it with yet.
record(options: RecordingOptions = {}): Promise<CameraRecording | null> Record a video, resolving once the recording stops: stopRecording() , a maxDuration (in seconds) or maxFileSize (in bytes) reached, or the preview stopping. The view needs mode="video" , and the microphone permission unless it has mute : without it, Android rejects and iOS records without sound. Null without the module, or before the view has reached the screen.
stopRecording(): Promise<void> Stop the recording in progress, if there is one: record() then resolves with the video.