Command palette

@yasinsensoy/native

React Native · Components

CameraView

Camera preview.

11 exports

Import

import { CameraView, Camera } from "@yasinsensoy/native";

CameraView

component

Camera preview. Capturing is done via ref. Camera permission must be granted beforehand (usePermission("camera")); without it onError is called with E_PERMISSION, and the preview opens automatically once permission is granted.

CameraView({ facing, flash, torch, zoom, active, onReady, onError, onRecordingStart, style, testID, ref, }: CameraViewProps): JSX.Element

Camera

module

About the device camera.

NameTypeDescription
isAvailable() => booleanDoes the device have a camera.
devices() => CameraFacing[]Available facings (["back", "front"]).

Camera facing.

type CameraFacing = "back" | "front"

Flash (when taking a photo).

type CameraFlash = "off" | "on" | "auto"

CameraPhoto

interface

A captured photo.

NameTypeDescription
uristringTemporary file (file://…); move it to your own folder to keep it.
widthnumberWidth with rotation applied (pixels).
heightnumberHeight with rotation applied (pixels).

CameraVideo

interface

A recorded video.

NameTypeDescription
uristringTemporary file (file://…; Android .mp4, iOS .mov).
durationnumberDuration (seconds).

Options for CameraHandle.takePhoto.

NameTypeDefaultDescription
quality?number0.9JPEG quality (0–1). Applied on Android; iOS uses the system quality.

RecordOptions

interface

Options for CameraHandle.startRecording.

NameTypeDefaultDescription
audio?booleantrueRecord audio. If microphone permission (ui.config permissions.microphone) is not granted, the video is recorded silent.
maxDuration?numberMaximum duration (seconds); recording stops automatically when reached.

CameraError

interface

Camera error (onError).

NameTypeDescription
codestringE_PERMISSION, E_NO_CAMERA, E_CAMERA…
messagestringError message.

CameraHandle

interface

Handle of CameraView (ref).

NameTypeDescription
takePhoto(options?: TakePhotoOptions): Promise<CameraPhoto>Takes a photo.
startRecording(options?: RecordOptions): Promise<CameraVideo>Starts video recording; the returned promise resolves when recording ends (stopRecording or duration).
stopRecording(): Promise<void>Stops recording.

Props of CameraView.

NameTypeDefaultDescription
facing?CameraFacing"back"Front or back camera.
flash?CameraFlash"off"Photo flash.
torch?booleanfalseTorch (continuous light).
zoom?number0Zoom: 0 (none) – 1 (the maximum the device allows, up to 10x).
active?booleantrueWhen false, the camera turns off (the view stays).
onReady?() => voidPreview started; capturing is now possible.
onError?(error: CameraError) => voidError (no permission, camera could not open…).
onRecordingStart?() => voidVideo recording started.
style?StyleProp<ViewStyle>Style; give it a size (the preview fills the area, edges are cropped).
testID?stringTest ID.
ref?Ref<CameraHandle>Handle.