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ourcesContent":["import {\n PermissionResponse,\n PermissionStatus,\n PermissionHookOptions,\n createPermissionHook,\n UnavailabilityError,\n} from 'expo-modules-core';\nimport * as React from 'react';\nimport { Platform, ViewProps } from 'react-native';\n\nimport ExpoBarCodeScannerModule from './ExpoBarCodeScannerModule';\nimport ExpoBarCodeScannerView from './ExpoBarCodeScannerView';\n\nconst { BarCodeType, Type } = ExpoBarCodeScannerModule;\n\nconst EVENT_THROTTLE_MS = 500;\n\n// @needsAudit\n/**\n * Those coordinates are represented in the coordinate space of the barcode source (e.g. when you\n * are using the barcode scanner view, these values are adjusted to the dimensions of the view).\n */\nexport type BarCodePoint = {\n /**\n * The `x` coordinate value.\n */\n x: number;\n /**\n * The `y` coordinate value.\n */\n y: number;\n};\n\n// @needsAudit\nexport type BarCodeSize = {\n /**\n * The height value.\n */\n height: number;\n /**\n * The width value.\n */\n width: number;\n};\n\n// @needsAudit\nexport type BarCodeBounds = {\n /**\n * The origin point of the bounding box.\n */\n origin: BarCodePoint;\n /**\n * The size of the bounding box.\n */\n size: BarCodeSize;\n};\n\n// @needsAudit\n/**\n * > __Note:__ `bounds` and `cornerPoints` are not always available. On iOS, for `code39` and `pdf417`\n * > you don't get those values. Moreover, on iOS, those values don't have to bounds the whole barcode.\n * > For some types, they will represent the area used by the scanner.\n */\nexport type BarCodeScannerResult = {\n /**\n * The barcode type.\n */\n type: string;\n /**\n * The information encoded in the bar code.\n */\n data: string;\n /**\n * The [BarCodeBounds](#barcodebounds) object.\n */\n bounds?: BarCodeBounds;\n /**\n * Corner points of the bounding box.\n */\n cornerPoints?: BarCodePoint[];\n};\n\n// @docsMissing\nexport type BarCodeEvent = BarCodeScannerResult & {\n target?: number;\n};\n\n// @docsMissing\nexport type BarCodeEventCallbackArguments = {\n nativeEvent: BarCodeEvent;\n};\n\n// @docsMissing\nexport type BarCodeScannedCallback = (params: BarCodeEvent) => void;\n\n// @needsAudit\nexport type BarCodeScannerProps = ViewProps & {\n /**\n * Camera facing. Use one of `BarCodeScanner.Constants.Type`. Use either `Type.front` or `Type.back`.\n * Same as `Camera.Constants.Type`.\n * @default Type.back\n */\n type?: 'front' | 'back' | number;\n /**\n * An array of bar code types. Usage: `BarCodeScanner.Constants.BarCodeType.<codeType>` where\n * `codeType` is one of these [listed above](#supported-formats). Defaults to all supported bar\n * code types. It is recommended to provide only the bar code formats you expect to scan to\n * minimize battery usage.\n *\n * For example: `barCodeTypes={[BarCodeScanner.Constants.BarCodeType.qr]}`.\n */\n barCodeTypes?: string[];\n /**\n * A callback that is invoked when a bar code has been successfully scanned. The callback is\n * provided with an [BarCodeScannerResult](#barcodescannerresult).\n * > __Note:__ Passing `undefined` to the `onBarCodeScanned` prop will result in no scanning. This\n * > can be used to effectively \"pause\" the scanner so that it doesn't continually scan even after\n * > data has been retrieved.\n */\n onBarCodeScanned?: BarCodeScannedCallback;\n};\n\nexport class BarCodeScanner extends React.Component<BarCodeScannerProps> {\n lastEvents: { [key: string]: any } = {};\n lastEventsTimes: { [key: string]: any } = {};\n\n static Constants = {\n BarCodeType,\n Type,\n };\n\n static ConversionTables = {\n type: Type,\n };\n\n static defaultProps = {\n type: Type.back,\n barCodeTypes: Object.values(BarCodeType),\n };\n\n // @needsAudit\n /**\n * Checks user's permissions for accessing the camera.\n * @return Return a promise that fulfills to an object of type [`PermissionResponse`](#permissionresponse).\n */\n static async getPermissionsAsync(): Promise<PermissionResponse> {\n return ExpoBarCodeScannerModule.getPermissionsAsync();\n }\n\n // @needsAudit\n /**\n * Asks the user to grant permissions for accessing the camera.\n *\n * On iOS this will require apps to specify the `NSCameraUsageDescription` entry in the `Info.plist`.\n * @return Return a promise that fulfills to an object of type [`PermissionResponse`](#permissionresponse).\n */\n static async requestPermissionsAsync(): Promise<PermissionResponse> {\n return ExpoBarCodeScannerModule.requestPermissionsAsync();\n }\n\n // @needsAudit\n /**\n * Check or request permissions for the barcode scanner.\n * This uses both `requestPermissionAsync` and `getPermissionsAsync` to interact with the permissions.\n *\n * @example\n * ```ts\n * const [status, requestPermission] = BarCodeScanner.usePermissions();\n * ```\n */\n static usePermissions = createPermissionHook({\n getMethod: BarCodeScanner.getPermissionsAsync,\n requestMethod: BarCodeScanner.requestPermissionsAsync,\n });\n\n // @needsAudit\n /**\n * Scan bar codes from the image given by the URL.\n * @param url URL to get the image from.\n * @param barCodeTypes An array of bar code types. Defaults to all supported bar code types on\n * the platform.\n * > __Note:__ Only QR codes are supported on iOS.\n * @return A possibly empty array of objects of the `BarCodeScannerResult` shape, where the type\n * refers to the bar code type that was scanned and the data is the information encoded in the bar\n * code.\n */\n static async scanFromURLAsync(\n url: string,\n barCodeTypes: string[] = Object.values(BarCodeType)\n ): Promise<BarCodeScannerResult[]> {\n if (!ExpoBarCodeScannerModule.scanFromURLAsync) {\n throw new UnavailabilityError('expo-barcode-scanner', 'scanFromURLAsync');\n }\n if (Array.isArray(barCodeTypes) && !barCodeTypes.length) {\n throw new Error('No barCodeTypes specified; provide at least one barCodeType for scanner');\n }\n\n if (Platform.OS === 'ios') {\n if (Array.isArray(barCodeTypes) && !barCodeTypes.includes(BarCodeType.qr)) {\n // Only QR type is supported on iOS, fail if one tries to use other types\n throw new Error('Only QR type is supported by scanFromURLAsync() on iOS');\n }\n // on iOS use only supported QR type\n return await ExpoBarCodeScannerModule.scanFromURLAsync(url, [BarCodeType.qr]);\n }\n\n // On other platforms, if barCodeTypes is not provided, use all available types\n return await ExpoBarCodeScannerModule.scanFromURLAsync(url, barCodeTypes);\n }\n\n render() {\n const nativeProps = this.convertNativeProps(this.props);\n const { onBarCodeScanned } = this.props;\n return (\n <ExpoBarCodeScannerView\n {...nativeProps}\n onBarCodeScanned={this.onObjectDetected(onBarCodeScanned)}\n />\n );\n }\n\n onObjectDetected =\n (callback?: BarCodeScannedCallback) =>\n ({ nativeEvent }: BarCodeEventCallbackArguments) => {\n const { type } = nativeEvent;\n if (\n this.lastEvents[type] &&\n this.lastEventsTimes[type] &&\n JSON.stringify(nativeEvent) === this.lastEvents[type] &&\n Date.now() - this.lastEventsTimes[type] < EVENT_THROTTLE_MS\n ) {\n return;\n }\n\n if (callback) {\n callback(nativeEvent);\n this.lastEventsTimes[type] = new Date();\n this.lastEvents[type] = JSON.stringify(nativeEvent);\n }\n };\n\n convertNativeProps(props: BarCodeScannerProps) {\n const nativeProps: BarCodeScannerProps = {};\n\n for (const [key, value] of Object.entries(props)) {\n if (typeof value === 'string' && BarCodeScanner.ConversionTables[key]) {\n nativeProps[key] = BarCodeScanner.ConversionTables[key][value];\n } else {\n nativeProps[key] = value;\n }\n }\n\n return nativeProps;\n }\n}\n\nexport { PermissionResponse, PermissionStatus, PermissionHookOptions };\nexport const {\n Constants,\n getPermissionsAsync,\n requestPermissionsAsync,\n usePermissions,\n scanFromURLAsync,\n} = BarCodeScanner;\n"]}
\No newline at end of file