feat: add onStatusChange callback (#2003)
This commit is contained in:
parent
57bc327d84
commit
4bcf88e99a
@ -305,6 +305,15 @@ Function to be called when native code emit onCameraReady event, when camera is
|
||||
|
||||
Function to be called when native code emit onMountError event, when there is a problem mounting the camera.
|
||||
|
||||
#### `onStatusChange`
|
||||
|
||||
Function to be called when native code emits status changes in relation to authorization changes.
|
||||
|
||||
Event contains the following fields:
|
||||
|
||||
- `cameraStatus` - one of the [CameraStatus](#status) values
|
||||
- `recordAudioPermissionStatus` - one of the [RecordAudioPermissionStatus](#recordAudioPermissionStatus) values
|
||||
|
||||
#### `Android` `onPictureTaken`
|
||||
|
||||
Function to be called when native code emit onPictureTaken event, when camera has taken a picture.
|
||||
@ -512,7 +521,7 @@ Supported options:
|
||||
|
||||
- `maxFileSize` (int greater than 0). Specifies the maximum file size, in bytes, of the video to be recorded. For 1mb, for example, use 1\*1024\*1024. If nothing is specified, no size limit will be used.
|
||||
|
||||
- `mute` (any value). (_This value will automatically be set to true if the `captureAudio` has not been passed to the Camera component_) If this flag is given in the option with any value, the video to be recorded will be mute. If nothing is specified, video will NOT be muted.
|
||||
- `mute` (any value). (_This value will automatically be set to true if the `captureAudio` has not been passed to the Camera component_) If this flag is given in the option with any value, the video to be recorded will be mute. If nothing is specified, video will NOT be muted.
|
||||
**Note:** The recommended way of recording audio without sound passing captureAudio: false to the Camera component.
|
||||
The `mute` parameter is likely to become deprecated in the near future.
|
||||
|
||||
|
||||
@ -135,6 +135,7 @@ type PropsType = typeof View.props & {
|
||||
focusDepth?: number,
|
||||
type?: number | string,
|
||||
onCameraReady?: Function,
|
||||
onStatusChange?: Function,
|
||||
onBarCodeRead?: Function,
|
||||
onPictureSaved?: Function,
|
||||
onGoogleVisionBarcodesDetected?: Function,
|
||||
@ -264,6 +265,7 @@ export default class Camera extends React.Component<PropsType, StateType> {
|
||||
focusDepth: PropTypes.number,
|
||||
onMountError: PropTypes.func,
|
||||
onCameraReady: PropTypes.func,
|
||||
onStatusChange: PropTypes.func,
|
||||
onBarCodeRead: PropTypes.func,
|
||||
onPictureSaved: PropTypes.func,
|
||||
onGoogleVisionBarcodesDetected: PropTypes.func,
|
||||
@ -465,6 +467,12 @@ export default class Camera extends React.Component<PropsType, StateType> {
|
||||
}
|
||||
};
|
||||
|
||||
_onStatusChange = () => {
|
||||
if (this.props.onStatusChange) {
|
||||
this.props.onStatusChange({ cameraStatus: this.getStatus(), recordAudioPermissionStatus: this.state.recordAudioPermissionStatus });
|
||||
}
|
||||
};
|
||||
|
||||
_onPictureSaved = ({ nativeEvent }: EventCallbackArgumentsType) => {
|
||||
if (this.props.onPictureSaved) {
|
||||
this.props.onPictureSaved(nativeEvent);
|
||||
@ -523,7 +531,7 @@ export default class Camera extends React.Component<PropsType, StateType> {
|
||||
isAuthorized: hasCameraPermissions,
|
||||
isAuthorizationChecked: true,
|
||||
recordAudioPermissionStatus,
|
||||
});
|
||||
}, this._onStatusChange);
|
||||
}
|
||||
|
||||
getStatus = (): Status => {
|
||||
|
||||
2
types/index.d.ts
vendored
2
types/index.d.ts
vendored
@ -141,6 +141,7 @@ export interface RNCameraProps {
|
||||
captureAudio?: boolean;
|
||||
|
||||
onCameraReady?(): void;
|
||||
onStatusChange?(event: { status: CameraStatus, recordAudioPermissionStatus: keyof RecordAudioPermissionStatus }): void;
|
||||
onMountError?(error: { message: string }): void;
|
||||
|
||||
/** Value: float from 0 to 1.0 */
|
||||
@ -244,6 +245,7 @@ interface TakePictureOptions {
|
||||
width?: number;
|
||||
mirrorImage?: boolean;
|
||||
doNotSave?: boolean;
|
||||
pauseAfterCapture?: boolean;
|
||||
|
||||
/** Android only */
|
||||
skipProcessing?: boolean;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user