react-native-vision-camera
Version:
VisionCamera is the fastest and most powerful Camera for react-native.
189 lines (188 loc) • 7.39 kB
TypeScript
import type { CameraController } from '../specs/CameraController.nitro';
import type { CameraPosition } from '../specs/common-types/CameraPosition';
import type { Constraint } from '../specs/common-types/Constraint';
import type { MirrorMode } from '../specs/common-types/MirrorMode';
import type { OrientationSource } from '../specs/common-types/OrientationSource';
import type { CameraDevice } from '../specs/inputs/CameraDevice.nitro';
import type { CameraOutput } from '../specs/outputs/CameraOutput.nitro';
import type { InterruptionReason } from '../specs/session/CameraSession.nitro';
import type { CameraSessionConfig } from '../specs/session/CameraSessionConfig.nitro';
export interface CameraProps {
/**
* Starts the {@linkcode CameraSession} when set to `true`, and stops it
* when set back to `false`.
*
* @see {@linkcode CameraSession.start | CameraSession.start()}
* @see {@linkcode CameraSession.stop | CameraSession.stop()}
* @see {@linkcode CameraSession.isRunning}
*/
isActive: boolean;
/**
* The {@linkcode CameraDevice} to open, or a {@linkcode CameraPosition}
* (e.g. `'back'`) to auto-pick a matching device via
* {@linkcode getCameraDevice | getCameraDevice(...)}.
*
* @see {@linkcode CameraSessionConnection.input}
*/
device: CameraDevice | CameraPosition;
/**
* The {@linkcode CameraOutput}s the {@linkcode device} will stream into.
*
* @see {@linkcode CameraSessionConnection.outputs}
* @see {@linkcode CameraOutputConfiguration.output}
*/
outputs?: CameraOutput[];
/**
* {@linkcode Constraint}s (e.g. `{ fps: 60 }`) that the Camera pipeline
* will try to match when configuring the {@linkcode CameraSession}.
*
* @see {@linkcode CameraSessionConnection.constraints}
*/
constraints?: Constraint[];
/**
* Called once the given {@linkcode constraints} have been fully resolved
* into a concrete {@linkcode CameraSessionConfig}.
*
* @see {@linkcode CameraSessionConnection.onSessionConfigSelected}
*/
onSessionConfigSelected?: (config: CameraSessionConfig) => void;
/**
* Set a desired {@linkcode OrientationSource}
* for automatically applying {@linkcode CameraOrientation}
* to all {@linkcode outputs}, or `'custom'` if you
* prefer to manually specify {@linkcode CameraOrientation}
* yourself.
*
* @see {@linkcode CameraOutput.outputOrientation}
*/
orientationSource?: OrientationSource | 'custom';
/**
* Sets whether the {@linkcode CameraOutput}s are mirrored along
* the vertical axis. {@linkcode MirrorMode | 'auto'} mirrors
* automatically on selfie cameras.
*
* @see {@linkcode CameraOutputConfiguration.mirrorMode}
* @default 'auto'
*/
mirrorMode?: MirrorMode;
/**
* If `true`, auto-focus transitions are performed slower and smoother
* to appear less intrusive in video recordings.
*
* @see {@linkcode CameraControllerConfiguration.enableSmoothAutoFocus}
* @platform iOS
* @default false
*/
enableSmoothAutoFocus?: boolean;
/**
* If `true`, the Camera pipeline may extend exposure times (effectively
* dropping frame rate) in low-light scenes to receive more light.
*
* @see {@linkcode CameraControllerConfiguration.enableLowLightBoost}
* @default false
*/
enableLowLightBoost?: boolean;
/**
* If `true`, geometric distortion at the edges (e.g. on ultra-wide-angle
* cameras) is corrected, at the cost of a small amount of field of view.
*
* @see {@linkcode CameraControllerConfiguration.enableDistortionCorrection}
* @platform iOS
* @default true
*/
enableDistortionCorrection?: boolean;
/**
* A getter for the initial zoom value to apply when the
* {@linkcode CameraController} is created. Later, the zoom can be
* adjusted via {@linkcode CameraController.setZoom | CameraController.setZoom(...)}.
*
* @see {@linkcode CameraSessionConnection.initialZoom}
*/
getInitialZoom?: () => number | undefined;
/**
* A getter for the initial exposure bias to apply when the
* {@linkcode CameraController} is created. Later, the exposure bias can be
* adjusted via {@linkcode CameraController.setExposureBias | CameraController.setExposureBias(...)}.
*
* @see {@linkcode CameraSessionConnection.initialExposureBias}
*/
getInitialExposureBias?: () => number | undefined;
/**
* Called whenever the {@linkcode CameraSession}
* has been configured with new connections via
* {@linkcode CameraSession.configure | configure(...)}
* and connections to the individual outputs are formed.
*
* This is a good place to check output
* capabilities, such as {@linkcode CameraVideoOutput.getSupportedVideoCodecs | CameraVideoOutput.getSupportedVideoCodecs()}
*/
onConfigured?: () => void;
/**
* Called when the {@linkcode CameraSession}
* has been started.
*
* @see {@linkcode CameraSession.addOnStartedListener}
*/
onStarted?: () => void;
/**
* Called when the {@linkcode CameraSession}
* has been stopped.
*
* @see {@linkcode CameraSession.addOnStoppedListener}
*/
onStopped?: () => void;
/**
* Called whenever the {@linkcode CameraSession}
* has encountered an error.
*
* @see {@linkcode CameraSession.addOnErrorListener}
*/
onError?: (error: Error) => void;
/**
* Called whenever the {@linkcode CameraSession}
* has encountered an interruption of the given
* {@linkcode InterruptionReason}.
* Interruptions are temporarily.
*
* @see {@linkcode CameraSession.addOnInterruptionStartedListener}
*/
onInterruptionStarted?: (interruption: InterruptionReason) => void;
/**
* Called when a previous interruption
* has ended and the {@linkcode CameraSession}
* is running uninterrupted again.
*
* @see {@linkcode CameraSession.addOnInterruptionEndedListener}
*/
onInterruptionEnded?: () => void;
/**
* Called when the subject area substantially changes,
* e.g. when the user pans away from a scene that was
* previously in focus.
*
* This is a good point to reset any locked AE/AF/AWB
* focus states back to continuously auto-focus.
*
* @see {@linkcode CameraController.addSubjectAreaChangedListener}
* @platform iOS
*/
onSubjectAreaChanged?: () => void;
}
/**
* Use the Camera.
*
* This creates a {@linkcode CameraSession}, manages
* the input and outputs (including orientation and
* mirror modes), wraps listeners as stable React
* callbacks, and returns a {@linkcode CameraController}.
*
* @example
* ```ts
* const camera = useCamera({
* isActive: true,
* device: 'back',
* outputs: []
* })
* ```
*/
export declare function useCamera({ isActive, device, outputs, constraints, onSessionConfigSelected, mirrorMode, onConfigured, orientationSource, onStarted, onStopped, onError, onInterruptionStarted, onInterruptionEnded, onSubjectAreaChanged, enableDistortionCorrection, enableLowLightBoost, enableSmoothAutoFocus, getInitialExposureBias, getInitialZoom, }: CameraProps): CameraController | undefined;