UNPKG

expo-camera

Version:

A React component that renders a preview for the device's either front or back camera. Camera's parameters like zoom, auto focus, white balance and flash mode are adjustable. With expo-camera, one can also take photos and record videos that are saved to t

47 lines (36 loc) 1.36 kB
import { Platform } from 'expo-modules-core'; import { CameraNativeProps, CameraType, FlashMode, CameraViewProps } from '../Camera.types'; import CameraManager from '../ExpoCameraManager'; // Values under keys from this object will be transformed to native options export const ConversionTables: { type: Record<keyof CameraType, CameraNativeProps['facing']>; flash: Record<keyof FlashMode, CameraNativeProps['flashMode']>; } = { type: CameraManager.Type, flash: CameraManager.FlashMode, }; export function convertNativeProps(props?: CameraViewProps): CameraNativeProps { if (!props || typeof props !== 'object') { return {}; } const nativeProps: CameraNativeProps = {}; for (const [key, value] of Object.entries(props)) { if (typeof value === 'string' && ConversionTables[key]) { nativeProps[key] = ConversionTables[key][value]; } else { nativeProps[key] = value; } } return nativeProps; } export function ensureNativeProps(props?: CameraViewProps): CameraNativeProps { const newProps = convertNativeProps(props); newProps.barcodeScannerEnabled = !!props?.onBarcodeScanned; newProps.flashMode = props?.flash ?? 'off'; newProps.mute = props?.mute ?? false; newProps.autoFocus = props?.autofocus ?? 'off'; if (Platform.OS !== 'web') { delete newProps.poster; } return newProps; }