/* * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. */ import type { ViewProps } from "react-native/Libraries/Components/View/ViewPropTypes";; import type { HostComponent } from "react-native"; import codegenNativeComponent from "react-native/Libraries/Utilities/codegenNativeComponent"; import { BubblingEventHandler, Float, Int32, WithDefault } from "react-native/Libraries/Types/CodegenTypes"; import codegenNativeCommands from "react-native/Libraries/Utilities/codegenNativeCommands"; import { PhotoFile } from "./types/PhotoFile"; import { Code, CodeScannerFrame } from "./types/CodeScanner"; import { Point } from "./types/Point"; import { RecordVideoOptions } from "./types/VideoFile"; export interface TakePhotoOptions { flash?: WithDefault<'on' | 'off' | 'auto', 'auto'> enableAutoRedEyeReduction?: WithDefault; enableAutoDistortionCorrection?: WithDefault; enableShutterSound?: WithDefault; } type Orientation = WithDefault<'portrait' | 'portrait-upside-down' | 'landscape-left' | 'landscape-right', 'portrait'> type AutoFocusSystem = WithDefault<'contrast-detection' | 'phase-detection' | 'none', 'contrast-detection'> type VideoStabilizationMode = 'off' | 'standard' | 'cinematic' | 'cinematic-extended' | 'auto'; type CameraPosition = WithDefault<'front' | 'back' | 'external', 'front'> type PhysicalCameraDeviceType = 'ultra-wide-angle-camera' | 'wide-angle-camera' | 'telephoto-camera' interface CameraDeviceFormat { photoHeight: Int32 photoWidth: Int32 videoHeight: Int32 videoWidth: Int32 maxISO: Int32 minISO: Int32 fieldOfView: Int32 supportsVideoHdr: boolean supportsPhotoHdr: boolean supportsDepthCapture: boolean minFps: Int32 maxFps: Int32 autoFocusSystem?: AutoFocusSystem videoStabilizationModes?: WithDefault, null> } interface CameraDevice { id: string physicalDevices?: WithDefault, null> position?: CameraPosition name: string hasFlash: boolean hasTorch: boolean minFocusDistance: Int32 isMultiCam: boolean minZoom: Float maxZoom: Float neutralZoom: Float minExposure: Float maxExposure: Float formats: CameraDeviceFormat[] supportsLowLightBoost: boolean supportsRawCapture: boolean supportsFocus: boolean hardwareLevel?: WithDefault<'legacy' | 'limited' | 'full', 'legacy'> sensorOrientation?: Orientation } type CodeType = | 'code-128' | 'code-39' | 'code-93' | 'codabar' | 'ean-13' | 'ean-8' | 'itf' | 'upc-e' | 'upc-a' | 'qr' | 'pdf-417' | 'aztec' | 'data-matrix' interface CodeScanner { codeTypes?: WithDefault, null>; onCodeScanned: (codes: Code[], frame: CodeScannerFrame) => void regionOfInterest?: { x: Int32 y: Int32 width: Int32 height: Int32 } } export interface NativeVisionCameraProps extends ViewProps { videoAspectRatio?: Int32; photoAspectRatio?: Int32; isMirrored: boolean; codeScanner?: CodeScanner; fps?: WithDefault; videoHdr?: WithDefault; isActive: boolean; preview?: WithDefault; device?: CameraDevice; resizeMode?: WithDefault<'cover' | 'contain', 'cover'>; enableZoomGesture?: WithDefault; exposure?: WithDefault; zoom?: WithDefault; audio?: WithDefault; video?: WithDefault; torch?: WithDefault<'off' | 'on', 'off'>; photo?: WithDefault; videoStabilizationMode?: WithDefault; androidPreviewViewType?: WithDefault<'surface-view' | 'texture-view', 'surface-view'>; enableLocation?: WithDefault; photoQualityBalance?: WithDefault<'speed' | 'balanced' | 'quality', 'balanced'>; onStarted?: BubblingEventHandler>; onStopped?: BubblingEventHandler>; onInitialized?: BubblingEventHandler>; onShutter?: BubblingEventHandler<{ type: 'photo' | 'snapshot' }>; onError?: BubblingEventHandler<{ error: string }>; onCodeScanned?: (codes: Code[], frame: CodeScannerFrame) => void; } // export interface Point export type VisionCameraComponentType = HostComponent export interface VisionCameraCommandsType { requestLocationPermission(viewRef: React.ElementRef): any; getLocationPermissionStatus(viewRef: React.ElementRef): any; requestMicrophonePermission(viewRef: React.ElementRef): any; getMicrophonePermissionStatus(viewRef: React.ElementRef): any; requestCameraPermission(viewRef: React.ElementRef): any; getCameraPermissionStatus(viewRef: React.ElementRef): any; addCameraDevicesChangedListener(viewRef: React.ElementRef): any; getAvailableCameraDevices(viewRef: React.ElementRef): any; takePhoto: (viewRef: React.ElementRef, options?: TakePhotoOptions) => Promise; focus: (viewRef: React.ElementRef, point: Point) => Promise; setIsActive: (viewRef: React.ElementRef, isActive: boolean) => Promise; startRecording: (viewRef: React.ElementRef, options: RecordVideoOptions) => void; stopRecording: (viewRef: React.ElementRef) => void; pauseRecording: (viewRef: React.ElementRef) => void; resumeRecording: (viewRef: React.ElementRef) => void; cancelRecording: (viewRef: React.ElementRef) => void; } export const VisionCameraCommands: VisionCameraCommandsType = codegenNativeCommands({ supportedCommands: [ 'takePhoto', 'focus', 'setIsActive', 'startRecording', 'stopRecording', 'pauseRecording', 'resumeRecording', 'cancelRecording', 'getAvailableCameraDevices', 'addCameraDevicesChangedListener', 'getCameraPermissionStatus', 'requestCameraPermission', 'getMicrophonePermissionStatus', 'requestMicrophonePermission', 'getLocationPermissionStatus', 'requestLocationPermission', ], }); export default codegenNativeComponent( "VisionCameraView" ) as VisionCameraComponentType;