UNPKG

5.91 kBTypeScriptView Raw
1import { PermissionResponse, PermissionStatus, PermissionHookOptions } from 'expo-modules-core';
2import * as React from 'react';
3import { ViewProps } from 'react-native';
4/**
5 * Those coordinates are represented in the coordinate space of the barcode source (e.g. when you
6 * are using the barcode scanner view, these values are adjusted to the dimensions of the view).
7 */
8export declare type BarCodePoint = {
9 /**
10 * The `x` coordinate value.
11 */
12 x: number;
13 /**
14 * The `y` coordinate value.
15 */
16 y: number;
17};
18export declare type BarCodeSize = {
19 /**
20 * The height value.
21 */
22 height: number;
23 /**
24 * The width value.
25 */
26 width: number;
27};
28export declare type BarCodeBounds = {
29 /**
30 * The origin point of the bounding box.
31 */
32 origin: BarCodePoint;
33 /**
34 * The size of the bounding box.
35 */
36 size: BarCodeSize;
37};
38/**
39 * > __Note:__ `bounds` and `cornerPoints` are not always available. On iOS, for `code39` and `pdf417`
40 * > you don't get those values. Moreover, on iOS, those values don't have to bounds the whole barcode.
41 * > For some types, they will represent the area used by the scanner.
42 */
43export declare type BarCodeScannerResult = {
44 /**
45 * The barcode type.
46 */
47 type: string;
48 /**
49 * The information encoded in the bar code.
50 */
51 data: string;
52 /**
53 * The [BarCodeBounds](#barcodebounds) object.
54 */
55 bounds?: BarCodeBounds;
56 /**
57 * Corner points of the bounding box.
58 */
59 cornerPoints?: BarCodePoint[];
60};
61export declare type BarCodeEvent = BarCodeScannerResult & {
62 target?: number;
63};
64export declare type BarCodeEventCallbackArguments = {
65 nativeEvent: BarCodeEvent;
66};
67export declare type BarCodeScannedCallback = (params: BarCodeEvent) => void;
68export declare type BarCodeScannerProps = ViewProps & {
69 /**
70 * Camera facing. Use one of `BarCodeScanner.Constants.Type`. Use either `Type.front` or `Type.back`.
71 * Same as `Camera.Constants.Type`.
72 * @default Type.back
73 */
74 type?: 'front' | 'back' | number;
75 /**
76 * An array of bar code types. Usage: `BarCodeScanner.Constants.BarCodeType.<codeType>` where
77 * `codeType` is one of these [listed above](#supported-formats). Defaults to all supported bar
78 * code types. It is recommended to provide only the bar code formats you expect to scan to
79 * minimize battery usage.
80 *
81 * For example: `barCodeTypes={[BarCodeScanner.Constants.BarCodeType.qr]}`.
82 */
83 barCodeTypes?: string[];
84 /**
85 * A callback that is invoked when a bar code has been successfully scanned. The callback is
86 * provided with an [BarCodeScannerResult](#barcodescannerresult).
87 * > __Note:__ Passing `undefined` to the `onBarCodeScanned` prop will result in no scanning. This
88 * > can be used to effectively "pause" the scanner so that it doesn't continually scan even after
89 * > data has been retrieved.
90 */
91 onBarCodeScanned?: BarCodeScannedCallback;
92};
93export declare class BarCodeScanner extends React.Component<BarCodeScannerProps> {
94 lastEvents: {
95 [key: string]: any;
96 };
97 lastEventsTimes: {
98 [key: string]: any;
99 };
100 static Constants: {
101 BarCodeType: any;
102 Type: any;
103 };
104 static ConversionTables: {
105 type: any;
106 };
107 static defaultProps: {
108 type: any;
109 barCodeTypes: unknown[];
110 };
111 /**
112 * Checks user's permissions for accessing the camera.
113 * @return Return a promise that fulfills to an object of type [`PermissionResponse`](#permissionresponse).
114 */
115 static getPermissionsAsync(): Promise<PermissionResponse>;
116 /**
117 * Asks the user to grant permissions for accessing the camera.
118 *
119 * On iOS this will require apps to specify the `NSCameraUsageDescription` entry in the `Info.plist`.
120 * @return Return a promise that fulfills to an object of type [`PermissionResponse`](#permissionresponse).
121 */
122 static requestPermissionsAsync(): Promise<PermissionResponse>;
123 /**
124 * Check or request permissions for the barcode scanner.
125 * This uses both `requestPermissionAsync` and `getPermissionsAsync` to interact with the permissions.
126 *
127 * @example
128 * ```ts
129 * const [status, requestPermission] = BarCodeScanner.usePermissions();
130 * ```
131 */
132 static usePermissions: (options?: PermissionHookOptions<object> | undefined) => [PermissionResponse | null, () => Promise<PermissionResponse>, () => Promise<PermissionResponse>];
133 /**
134 * Scan bar codes from the image given by the URL.
135 * @param url URL to get the image from.
136 * @param barCodeTypes An array of bar code types. Defaults to all supported bar code types on
137 * the platform.
138 * > __Note:__ Only QR codes are supported on iOS.
139 * @return A possibly empty array of objects of the `BarCodeScannerResult` shape, where the type
140 * refers to the bar code type that was scanned and the data is the information encoded in the bar
141 * code.
142 */
143 static scanFromURLAsync(url: string, barCodeTypes?: string[]): Promise<BarCodeScannerResult[]>;
144 render(): JSX.Element;
145 onObjectDetected: (callback?: BarCodeScannedCallback | undefined) => ({ nativeEvent }: BarCodeEventCallbackArguments) => void;
146 convertNativeProps(props: BarCodeScannerProps): BarCodeScannerProps;
147}
148export { PermissionResponse, PermissionStatus, PermissionHookOptions };
149export declare const Constants: {
150 BarCodeType: any;
151 Type: any;
152}, getPermissionsAsync: typeof BarCodeScanner.getPermissionsAsync, requestPermissionsAsync: typeof BarCodeScanner.requestPermissionsAsync, usePermissions: (options?: PermissionHookOptions<object> | undefined) => [PermissionResponse | null, () => Promise<PermissionResponse>, () => Promise<PermissionResponse>], scanFromURLAsync: typeof BarCodeScanner.scanFromURLAsync;