1import {
2  PermissionResponse,
3  PermissionStatus,
4  PermissionExpiration,
5  PermissionHookOptions,
6} from 'expo-modules-core';
7import { ViewProps } from 'react-native';
8
9export enum CameraType {
10  /**
11   * @platforms ios, android, web
12   */
13  front = 'front',
14  /**
15   * @platforms ios, android, web
16   */
17  back = 'back',
18}
19
20export enum FlashMode {
21  /**
22   * @platforms ios, android, web
23   */
24  on = 'on',
25  /**
26   * @platforms ios, android, web
27   */
28  off = 'off',
29  /**
30   * @platforms ios, android, web
31   */
32  auto = 'auto',
33  /**
34   * @platforms ios, android, web
35   */
36  torch = 'torch',
37}
38
39export enum AutoFocus {
40  /**
41   * @platforms ios, android, web
42   */
43  on = 'on',
44  /**
45   * @platforms ios, android, web
46   */
47  off = 'off',
48  /**
49   * @platforms web
50   */
51  auto = 'auto',
52  /**
53   * @platforms web
54   */
55  singleShot = 'singleShot',
56}
57
58export enum WhiteBalance {
59  /**
60   * @platforms ios, android, web
61   */
62  auto = 'auto',
63  /**
64   * @platforms ios, android
65   */
66  sunny = 'sunny',
67  /**
68   * @platforms ios, android
69   */
70  cloudy = 'cloudy',
71  /**
72   * @platforms ios, android
73   */
74  shadow = 'shadow',
75  /**
76   * @platforms ios, android
77   */
78  incandescent = 'incandescent',
79  /**
80   * @platforms ios, android
81   */
82  fluorescent = 'fluorescent',
83  /**
84   * @platforms web
85   */
86  continuous = 'continuous',
87  /**
88   * @platforms web
89   */
90  manual = 'manual',
91}
92
93export enum ImageType {
94  png = 'png',
95  jpg = 'jpg',
96}
97
98/**
99 * This option specifies what codec to use when recording a video.
100 */
101export enum VideoCodec {
102  /**
103   * @platforms ios
104   */
105  H264 = 'avc1',
106  /**
107   * @platforms ios
108   */
109  HEVC = 'hvc1',
110  /**
111   * @platforms ios
112   */
113  JPEG = 'jpeg',
114  /**
115   * @platforms ios
116   */
117  AppleProRes422 = 'apcn',
118  /**
119   * @platforms ios
120   */
121  AppleProRes4444 = 'ap4h',
122}
123
124export type ImageParameters = {
125  imageType: ImageType;
126  quality: number | null;
127};
128
129export type ImageSize = {
130  width: number;
131  height: number;
132};
133
134export type WebCameraSettings = Partial<{
135  autoFocus: string;
136  flashMode: string;
137  whiteBalance: string;
138  exposureCompensation: number;
139  colorTemperature: number;
140  iso: number;
141  brightness: number;
142  contrast: number;
143  saturation: number;
144  sharpness: number;
145  focusDistance: number;
146  zoom: number;
147}>;
148
149export type CapturedPicture = {
150  width: number;
151  height: number;
152  uri: string;
153  base64?: string;
154  // note(bacon): The types are currently only defined for web.
155  exif?: Partial<MediaTrackSettings>;
156};
157
158export type CameraPictureOptions = {
159  quality?: number;
160  base64?: boolean;
161  exif?: boolean;
162  onPictureSaved?: (picture: CameraCapturedPicture) => void;
163  // TODO(Bacon): Is it possible to implement this in the browser?
164  skipProcessing?: boolean;
165  // Web-only
166  scale?: number;
167  imageType?: ImageType;
168  isImageMirror?: boolean;
169  // internal
170  id?: number;
171  fastMode?: boolean;
172};
173
174export type CameraRecordingOptions = {
175  maxDuration?: number;
176  maxFileSize?: number;
177  quality?: number | string;
178  mute?: boolean;
179  mirror?: boolean;
180  // Android
181  videoBitrate?: number;
182  // iOS
183  codec?: VideoCodec;
184};
185
186export type CameraCapturedPicture = {
187  width: number;
188  height: number;
189  uri: string;
190  base64?: string;
191  exif?: any;
192};
193
194export type PictureSavedListener = (event: {
195  nativeEvent: { data: CapturedPicture; id: number };
196}) => void;
197
198export type CameraReadyListener = () => void;
199
200export type MountErrorListener = (event: { nativeEvent: CameraMountError }) => void;
201
202export type CameraMountError = { message: string };
203
204type Point = {
205  x: number;
206  y: number;
207};
208
209export type BarCodePoint = Point;
210
211export type BarCodeScanningResult = {
212  type: string;
213  data: string;
214  /** @platform web */
215  cornerPoints?: BarCodePoint[];
216};
217
218export type Face = {
219  faceID: number;
220  bounds: {
221    origin: Point;
222    size: {
223      height: number;
224      width: number;
225    };
226  };
227  rollAngle: number;
228  yawAngle: number;
229  smilingProbability: number;
230  leftEarPosition: Point;
231  rightEarPosition: Point;
232  leftEyePosition: Point;
233  leftEyeOpenProbability: number;
234  rightEyePosition: Point;
235  rightEyeOpenProbability: number;
236  leftCheekPosition: Point;
237  rightCheekPosition: Point;
238  mouthPosition: Point;
239  leftMouthPosition: Point;
240  rightMouthPosition: Point;
241  noseBasePosition: Point;
242};
243
244export type FaceDetectionResult = { faces: Face[] };
245
246export type ConstantsType = {
247  Type: typeof CameraType;
248  FlashMode: typeof FlashMode;
249  AutoFocus: typeof AutoFocus;
250  WhiteBalance: typeof WhiteBalance;
251  VideoQuality: any;
252  VideoStabilization: any;
253  VideoCodec: typeof VideoCodec;
254};
255
256export type CameraProps = ViewProps & {
257  type?: number | keyof typeof CameraType;
258  flashMode?: number | keyof typeof FlashMode;
259  whiteBalance?: number | keyof typeof WhiteBalance;
260  autoFocus?: boolean | number | keyof typeof AutoFocus;
261  zoom?: number;
262  ratio?: string;
263  focusDepth?: number;
264  onCameraReady?: Function;
265  useCamera2Api?: boolean;
266  pictureSize?: string;
267  videoStabilizationMode?: number;
268  onMountError?: (event: CameraMountError) => void;
269  barCodeScannerSettings?: object;
270  onBarCodeScanned?: (scanningResult: BarCodeScanningResult) => void;
271  faceDetectorSettings?: object;
272  onFacesDetected?: (faces: FaceDetectionResult) => void;
273  poster?: string;
274};
275
276export type CameraNativeProps = {
277  pointerEvents?: any;
278  style?: any;
279  ref?: Function;
280  onCameraReady?: CameraReadyListener;
281  onMountError?: MountErrorListener;
282  onBarCodeScanned?: (event: { nativeEvent: BarCodeScanningResult }) => void;
283  onFacesDetected?: (event: { nativeEvent: FaceDetectionResult }) => void;
284  onFaceDetectionError?: (event: { nativeEvent: Error }) => void;
285  onPictureSaved?: PictureSavedListener;
286  type?: number | string;
287  flashMode?: number | string;
288  autoFocus?: string | boolean | number;
289  focusDepth?: number;
290  zoom?: number;
291  whiteBalance?: number | string;
292  pictureSize?: string;
293  barCodeScannerSettings?: BarCodeSettings;
294  faceDetectorSettings?: object;
295  barCodeScannerEnabled?: boolean;
296  faceDetectorEnabled?: boolean;
297  // Android
298  ratio?: string;
299  useCamera2Api?: boolean;
300  // Web
301  poster?: string;
302};
303
304export type BarCodeSettings = {
305  barCodeTypes: string[];
306  interval?: number;
307};
308
309export { PermissionResponse, PermissionStatus, PermissionExpiration, PermissionHookOptions };
310