Extract CameraProps to separate file
This commit is contained in:
parent
069b72750a
commit
5bfcdf324e
148
src/Camera.tsx
148
src/Camera.tsx
@ -1,154 +1,17 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { requireNativeComponent, NativeModules, ViewProps, NativeSyntheticEvent, findNodeHandle, NativeMethods, Platform } from 'react-native';
|
import { requireNativeComponent, NativeModules, NativeSyntheticEvent, findNodeHandle, NativeMethods, Platform } from 'react-native';
|
||||||
import type { CameraPhotoCodec, CameraVideoCodec } from './CameraCodec';
|
import type { CameraPhotoCodec, CameraVideoCodec } from './CameraCodec';
|
||||||
import type { ColorSpace, CameraDeviceFormat, CameraDevice } from './CameraDevice';
|
import type { CameraDevice } from './CameraDevice';
|
||||||
import type { ErrorWithCause } from './CameraError';
|
import type { ErrorWithCause } from './CameraError';
|
||||||
import { CameraCaptureError, CameraRuntimeError, tryParseNativeCameraError, isErrorWithCause } from './CameraError';
|
import { CameraCaptureError, CameraRuntimeError, tryParseNativeCameraError, isErrorWithCause } from './CameraError';
|
||||||
import type { CameraPreset } from './CameraPreset';
|
import type { CameraProps } from './CameraProps';
|
||||||
import type { CodeType, Code } from './Code';
|
import type { Code } from './Code';
|
||||||
import type { PhotoFile, TakePhotoOptions } from './PhotoFile';
|
import type { PhotoFile, TakePhotoOptions } from './PhotoFile';
|
||||||
import type { Point } from './Point';
|
import type { Point } from './Point';
|
||||||
import type { TakeSnapshotOptions } from './Snapshot';
|
import type { TakeSnapshotOptions } from './Snapshot';
|
||||||
import type { RecordVideoOptions, VideoFile } from './VideoFile';
|
import type { RecordVideoOptions, VideoFile } from './VideoFile';
|
||||||
|
|
||||||
//#region Types
|
//#region Types
|
||||||
export interface CameraProps extends ViewProps {
|
|
||||||
/**
|
|
||||||
* The Camera Device to use.
|
|
||||||
*
|
|
||||||
* See the [Camera Devices](https://cuvent.github.io/react-native-vision-camera/docs/guides/devices) section in the documentation for more information about Camera Devices.
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* ```tsx
|
|
||||||
* const devices = useCameraDevices('wide-angle-camera')
|
|
||||||
* const device = devices.back
|
|
||||||
*
|
|
||||||
* return (
|
|
||||||
* <Camera
|
|
||||||
* device={device}
|
|
||||||
* isActive={true}
|
|
||||||
* style={StyleSheet.absoluteFill}
|
|
||||||
* />
|
|
||||||
* )
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
device: CameraDevice;
|
|
||||||
/**
|
|
||||||
* Whether the Camera should actively stream video frames, or not. See the [documentation about the `isActive` prop](https://cuvent.github.io/react-native-vision-camera/docs/guides/devices#the-isactive-prop) for more information.
|
|
||||||
*
|
|
||||||
* This can be compared to a Video component, where `isActive` specifies whether the video is paused or not.
|
|
||||||
*
|
|
||||||
* > Note: If you fully unmount the `<Camera>` component instead of using `isActive={false}`, the Camera will take a bit longer to start again. In return, it will use less resources since the Camera will be completely destroyed when unmounted.
|
|
||||||
*/
|
|
||||||
isActive: boolean;
|
|
||||||
|
|
||||||
//#region Common Props (torch, zoom)
|
|
||||||
/**
|
|
||||||
* Set the current torch mode.
|
|
||||||
*
|
|
||||||
* Note: The torch is only available on `"back"` cameras, and isn't supported by every phone.
|
|
||||||
*
|
|
||||||
* @default "off"
|
|
||||||
*/
|
|
||||||
torch?: 'off' | 'on';
|
|
||||||
/**
|
|
||||||
* Specifies the zoom factor of the current camera, in percent. (`0.0` - `1.0`)
|
|
||||||
*
|
|
||||||
* **Note:** Linearly increasing this value always appears logarithmic to the user.
|
|
||||||
*
|
|
||||||
* @default 0.0
|
|
||||||
*/
|
|
||||||
zoom?: number;
|
|
||||||
/**
|
|
||||||
* Enables or disables the native pinch to zoom gesture.
|
|
||||||
*
|
|
||||||
* If you want to implement a custom zoom gesture, see [the Zooming with Reanimated documentation](https://cuvent.github.io/react-native-vision-camera/docs/guides/animated).
|
|
||||||
*
|
|
||||||
* @default false
|
|
||||||
*/
|
|
||||||
enableZoomGesture?: boolean;
|
|
||||||
//#endregion
|
|
||||||
|
|
||||||
//#region Format/Preset selection
|
|
||||||
/**
|
|
||||||
* Automatically selects a camera format which best matches the given preset. Must be `undefined` when `format` is set!
|
|
||||||
*/
|
|
||||||
preset?: CameraPreset;
|
|
||||||
/**
|
|
||||||
* Selects a given format. Must be `undefined` when `preset` is set!
|
|
||||||
*/
|
|
||||||
format?: CameraDeviceFormat;
|
|
||||||
/**
|
|
||||||
* Specify the frames per second this camera should use. Make sure the given `format` includes a frame rate range with the given `fps`.
|
|
||||||
*
|
|
||||||
* Requires `format` to be set.
|
|
||||||
*/
|
|
||||||
fps?: number;
|
|
||||||
/**
|
|
||||||
* Enables or disables HDR on this camera device. Make sure the given `format` supports HDR mode.
|
|
||||||
*
|
|
||||||
* Requires `format` to be set.
|
|
||||||
*/
|
|
||||||
hdr?: boolean;
|
|
||||||
/**
|
|
||||||
* Enables or disables low-light boost on this camera device. Make sure the given `format` supports low-light boost.
|
|
||||||
*
|
|
||||||
* Requires `format` to be set.
|
|
||||||
*/
|
|
||||||
lowLightBoost?: boolean;
|
|
||||||
/**
|
|
||||||
* Specifies the color space to use for this camera device. Make sure the given `format` contains the given `colorSpace`.
|
|
||||||
*
|
|
||||||
* Requires `format` to be set.
|
|
||||||
*/
|
|
||||||
colorSpace?: ColorSpace;
|
|
||||||
//#endregion
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Also captures data from depth-perception sensors. (e.g. disparity maps)
|
|
||||||
*
|
|
||||||
* @default false
|
|
||||||
*/
|
|
||||||
enableDepthData?: boolean;
|
|
||||||
/**
|
|
||||||
* A boolean specifying whether the photo render pipeline is prepared for portrait effects matte delivery.
|
|
||||||
*
|
|
||||||
* When enabling this, you must also set `enableDepthData` to `true`.
|
|
||||||
*
|
|
||||||
* @platform iOS 12.0+
|
|
||||||
* @default false
|
|
||||||
*/
|
|
||||||
enablePortraitEffectsMatteDelivery?: boolean;
|
|
||||||
/**
|
|
||||||
* Indicates whether the photo render pipeline should be configured to deliver high resolution still images
|
|
||||||
*
|
|
||||||
* @default false
|
|
||||||
*/
|
|
||||||
enableHighResolutionCapture?: boolean;
|
|
||||||
|
|
||||||
//#region Events
|
|
||||||
/**
|
|
||||||
* Called when any kind of runtime error occured.
|
|
||||||
*/
|
|
||||||
onError?: (error: CameraRuntimeError) => void;
|
|
||||||
/**
|
|
||||||
* Called when the camera was successfully initialized.
|
|
||||||
*/
|
|
||||||
onInitialized?: () => void;
|
|
||||||
|
|
||||||
// TODO: Remove once frameProcessors land
|
|
||||||
/**
|
|
||||||
* Specify the code types this camera can scan. Will be removed with the addition of Frame Processors.
|
|
||||||
*/
|
|
||||||
scannableCodes?: CodeType[];
|
|
||||||
// TODO: Remove once frameProcessors land
|
|
||||||
/**
|
|
||||||
* Called when one or multiple codes have been scanned. Will be removed with the addition of Frame Processors.
|
|
||||||
*/
|
|
||||||
onCodeScanned?: (codes: Code[]) => void;
|
|
||||||
//#endregion
|
|
||||||
}
|
|
||||||
|
|
||||||
export type CameraPermissionStatus = 'authorized' | 'not-determined' | 'denied' | 'restricted';
|
export type CameraPermissionStatus = 'authorized' | 'not-determined' | 'denied' | 'restricted';
|
||||||
export type CameraPermissionRequestResult = 'authorized' | 'denied';
|
export type CameraPermissionRequestResult = 'authorized' | 'denied';
|
||||||
|
|
||||||
@ -167,7 +30,6 @@ type NativeCameraViewProps = Omit<CameraProps, 'device' | 'onInitialized' | 'onE
|
|||||||
onCodeScanned?: (event: NativeSyntheticEvent<OnCodeScannedEvent>) => void;
|
onCodeScanned?: (event: NativeSyntheticEvent<OnCodeScannedEvent>) => void;
|
||||||
};
|
};
|
||||||
type RefType = React.Component<NativeCameraViewProps> & Readonly<NativeMethods>;
|
type RefType = React.Component<NativeCameraViewProps> & Readonly<NativeMethods>;
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
// NativeModules automatically resolves 'CameraView' to 'CameraViewModule'
|
// NativeModules automatically resolves 'CameraView' to 'CameraViewModule'
|
||||||
@ -182,6 +44,7 @@ interface CameraState {
|
|||||||
cameraId?: string;
|
cameraId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//#region Camera Component
|
||||||
/**
|
/**
|
||||||
* ### A powerful `<Camera>` component.
|
* ### A powerful `<Camera>` component.
|
||||||
*
|
*
|
||||||
@ -552,6 +415,7 @@ export class Camera extends React.PureComponent<CameraProps, CameraState> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//#endregion
|
||||||
|
|
||||||
// requireNativeComponent automatically resolves 'CameraView' to 'CameraViewManager'
|
// requireNativeComponent automatically resolves 'CameraView' to 'CameraViewManager'
|
||||||
const NativeCameraView = requireNativeComponent<NativeCameraViewProps>(
|
const NativeCameraView = requireNativeComponent<NativeCameraViewProps>(
|
||||||
|
142
src/CameraProps.ts
Normal file
142
src/CameraProps.ts
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
import type { ViewProps } from 'react-native';
|
||||||
|
import type { CameraDevice, CameraDeviceFormat, ColorSpace } from './CameraDevice';
|
||||||
|
import type { CameraRuntimeError } from './CameraError';
|
||||||
|
import type { CameraPreset } from './CameraPreset';
|
||||||
|
import type { Code, CodeType } from './Code';
|
||||||
|
|
||||||
|
export interface CameraProps extends ViewProps {
|
||||||
|
/**
|
||||||
|
* The Camera Device to use.
|
||||||
|
*
|
||||||
|
* See the [Camera Devices](https://cuvent.github.io/react-native-vision-camera/docs/guides/devices) section in the documentation for more information about Camera Devices.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```tsx
|
||||||
|
* const devices = useCameraDevices('wide-angle-camera')
|
||||||
|
* const device = devices.back
|
||||||
|
*
|
||||||
|
* return (
|
||||||
|
* <Camera
|
||||||
|
* device={device}
|
||||||
|
* isActive={true}
|
||||||
|
* style={StyleSheet.absoluteFill}
|
||||||
|
* />
|
||||||
|
* )
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
device: CameraDevice;
|
||||||
|
/**
|
||||||
|
* Whether the Camera should actively stream video frames, or not. See the [documentation about the `isActive` prop](https://cuvent.github.io/react-native-vision-camera/docs/guides/devices#the-isactive-prop) for more information.
|
||||||
|
*
|
||||||
|
* This can be compared to a Video component, where `isActive` specifies whether the video is paused or not.
|
||||||
|
*
|
||||||
|
* > Note: If you fully unmount the `<Camera>` component instead of using `isActive={false}`, the Camera will take a bit longer to start again. In return, it will use less resources since the Camera will be completely destroyed when unmounted.
|
||||||
|
*/
|
||||||
|
isActive: boolean;
|
||||||
|
|
||||||
|
//#region Common Props (torch, zoom)
|
||||||
|
/**
|
||||||
|
* Set the current torch mode.
|
||||||
|
*
|
||||||
|
* Note: The torch is only available on `"back"` cameras, and isn't supported by every phone.
|
||||||
|
*
|
||||||
|
* @default "off"
|
||||||
|
*/
|
||||||
|
torch?: 'off' | 'on';
|
||||||
|
/**
|
||||||
|
* Specifies the zoom factor of the current camera, in percent. (`0.0` - `1.0`)
|
||||||
|
*
|
||||||
|
* **Note:** Linearly increasing this value always appears logarithmic to the user.
|
||||||
|
*
|
||||||
|
* @default 0.0
|
||||||
|
*/
|
||||||
|
zoom?: number;
|
||||||
|
/**
|
||||||
|
* Enables or disables the native pinch to zoom gesture.
|
||||||
|
*
|
||||||
|
* If you want to implement a custom zoom gesture, see [the Zooming with Reanimated documentation](https://cuvent.github.io/react-native-vision-camera/docs/guides/animated).
|
||||||
|
*
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
enableZoomGesture?: boolean;
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region Format/Preset selection
|
||||||
|
/**
|
||||||
|
* Automatically selects a camera format which best matches the given preset. Must be `undefined` when `format` is set!
|
||||||
|
*/
|
||||||
|
preset?: CameraPreset;
|
||||||
|
/**
|
||||||
|
* Selects a given format. Must be `undefined` when `preset` is set!
|
||||||
|
*/
|
||||||
|
format?: CameraDeviceFormat;
|
||||||
|
/**
|
||||||
|
* Specify the frames per second this camera should use. Make sure the given `format` includes a frame rate range with the given `fps`.
|
||||||
|
*
|
||||||
|
* Requires `format` to be set.
|
||||||
|
*/
|
||||||
|
fps?: number;
|
||||||
|
/**
|
||||||
|
* Enables or disables HDR on this camera device. Make sure the given `format` supports HDR mode.
|
||||||
|
*
|
||||||
|
* Requires `format` to be set.
|
||||||
|
*/
|
||||||
|
hdr?: boolean;
|
||||||
|
/**
|
||||||
|
* Enables or disables low-light boost on this camera device. Make sure the given `format` supports low-light boost.
|
||||||
|
*
|
||||||
|
* Requires `format` to be set.
|
||||||
|
*/
|
||||||
|
lowLightBoost?: boolean;
|
||||||
|
/**
|
||||||
|
* Specifies the color space to use for this camera device. Make sure the given `format` contains the given `colorSpace`.
|
||||||
|
*
|
||||||
|
* Requires `format` to be set.
|
||||||
|
*/
|
||||||
|
colorSpace?: ColorSpace;
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Also captures data from depth-perception sensors. (e.g. disparity maps)
|
||||||
|
*
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
enableDepthData?: boolean;
|
||||||
|
/**
|
||||||
|
* A boolean specifying whether the photo render pipeline is prepared for portrait effects matte delivery.
|
||||||
|
*
|
||||||
|
* When enabling this, you must also set `enableDepthData` to `true`.
|
||||||
|
*
|
||||||
|
* @platform iOS 12.0+
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
enablePortraitEffectsMatteDelivery?: boolean;
|
||||||
|
/**
|
||||||
|
* Indicates whether the photo render pipeline should be configured to deliver high resolution still images
|
||||||
|
*
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
enableHighResolutionCapture?: boolean;
|
||||||
|
|
||||||
|
//#region Events
|
||||||
|
/**
|
||||||
|
* Called when any kind of runtime error occured.
|
||||||
|
*/
|
||||||
|
onError?: (error: CameraRuntimeError) => void;
|
||||||
|
/**
|
||||||
|
* Called when the camera was successfully initialized.
|
||||||
|
*/
|
||||||
|
onInitialized?: () => void;
|
||||||
|
|
||||||
|
// TODO: Remove once frameProcessors land
|
||||||
|
/**
|
||||||
|
* Specify the code types this camera can scan. Will be removed with the addition of Frame Processors.
|
||||||
|
*/
|
||||||
|
scannableCodes?: CodeType[];
|
||||||
|
// TODO: Remove once frameProcessors land
|
||||||
|
/**
|
||||||
|
* Called when one or multiple codes have been scanned. Will be removed with the addition of Frame Processors.
|
||||||
|
*/
|
||||||
|
onCodeScanned?: (codes: Code[]) => void;
|
||||||
|
//#endregion
|
||||||
|
}
|
@ -4,6 +4,7 @@ export * from './CameraDevice';
|
|||||||
export * from './CameraError';
|
export * from './CameraError';
|
||||||
export * from './CameraPosition';
|
export * from './CameraPosition';
|
||||||
export * from './CameraPreset';
|
export * from './CameraPreset';
|
||||||
|
export * from './CameraProps';
|
||||||
export * from './Code';
|
export * from './Code';
|
||||||
export * from './PhotoFile';
|
export * from './PhotoFile';
|
||||||
export * from './Point';
|
export * from './Point';
|
||||||
|
Loading…
Reference in New Issue
Block a user