1import {
2  PermissionResponse,
3  PermissionStatus,
4  PermissionExpiration,
5  PermissionHookOptions,
6} from 'expo-modules-core';
7import type { ViewProps } from 'react-native';
8
9export enum CameraType {
10  front = 'front',
11  back = 'back',
12}
13
14export enum FlashMode {
15  on = 'on',
16  off = 'off',
17  auto = 'auto',
18  torch = 'torch',
19}
20
21export enum AutoFocus {
22  on = 'on',
23  off = 'off',
24  /**
25   * @platform web
26   */
27  auto = 'auto',
28  /**
29   * @platform web
30   */
31  singleShot = 'singleShot',
32}
33
34export enum WhiteBalance {
35  auto = 'auto',
36  /**
37   * @platform android
38   * @platform ios
39   */
40  sunny = 'sunny',
41  /**
42   * @platform android
43   * @platform ios
44   */
45  cloudy = 'cloudy',
46  /**
47   * @platform android
48   * @platform ios
49   */
50  shadow = 'shadow',
51  /**
52   * @platform android
53   * @platform ios
54   */
55  incandescent = 'incandescent',
56  /**
57   * @platform android
58   * @platform ios
59   */
60  fluorescent = 'fluorescent',
61  /**
62   * @platform web
63   */
64  continuous = 'continuous',
65  /**
66   * @platform web
67   */
68  manual = 'manual',
69}
70
71export enum ImageType {
72  png = 'png',
73  jpg = 'jpg',
74}
75
76/**
77 * This option specifies what codec to use when recording a video.
78 * @platform ios
79 */
80export enum VideoCodec {
81  H264 = 'avc1',
82  HEVC = 'hvc1',
83  JPEG = 'jpeg',
84  AppleProRes422 = 'apcn',
85  AppleProRes4444 = 'ap4h',
86}
87
88/**
89 * This option specifies the stabilization mode to use when recording a video.
90 * @platform ios
91 */
92export enum VideoStabilization {
93  off = 'off',
94  standard = 'standard',
95  cinematic = 'cinematic',
96  auto = 'auto',
97}
98
99// @docsMissing
100export enum VideoQuality {
101  '2160p' = '2160p',
102  '1080p' = '1080p',
103  '720p' = '720p',
104  '480p' = '480p',
105  '4:3' = '4:3',
106}
107
108// @docsMissing
109/**
110 * @hidden We do not expose related web methods in docs.
111 * @platform web
112 */
113export type ImageSize = {
114  width: number;
115  height: number;
116};
117
118// @docsMissing
119/**
120 * @hidden We do not expose related web methods in docs.
121 * @platform web
122 */
123export type WebCameraSettings = {
124  autoFocus?: string;
125  flashMode?: string;
126  whiteBalance?: string;
127  exposureCompensation?: number;
128  colorTemperature?: number;
129  iso?: number;
130  brightness?: number;
131  contrast?: number;
132  saturation?: number;
133  sharpness?: number;
134  focusDistance?: number;
135  zoom?: number;
136};
137
138// @needsAudit
139export type CameraCapturedPicture = {
140  /**
141   * Captured image width.
142   */
143  width: number;
144  /**
145   * Captured image height.
146   */
147  height: number;
148  /**
149   * On web, the value of `uri` is the same as `base64` because file system URLs are not supported in the browser.
150   */
151  uri: string;
152  /**
153   * A Base64 representation of the image.
154   */
155  base64?: string;
156  /**
157   * On Android and iOS this object may include various fields based on the device and operating system.
158   * On web, it is a partial representation of the [`MediaTrackSettings`](https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackSettings) dictionary.
159   */
160  exif?: Partial<MediaTrackSettings> | any;
161};
162
163// @needsAudit
164export type CameraPictureOptions = {
165  /**
166   * Specify the quality of compression, from 0 to 1. 0 means compress for small size, 1 means compress for maximum quality.
167   */
168  quality?: number;
169  /**
170   * Whether to also include the image data in Base64 format.
171   */
172  base64?: boolean;
173  /**
174   * Whether to also include the EXIF data for the image.
175   */
176  exif?: boolean;
177  /**
178   * Additional EXIF data to be included for the image. Only useful when `exif` option is set to `true`.
179   * @platform android
180   * @platform ios
181   */
182  additionalExif?: { [name: string]: any };
183  /**
184   * A callback invoked when picture is saved. If set, the promise of this method will resolve immediately with no data after picture is captured.
185   * The data that it should contain will be passed to this callback. If displaying or processing a captured photo right after taking it
186   * is not your case, this callback lets you skip waiting for it to be saved.
187   * @param picture
188   */
189  onPictureSaved?: (picture: CameraCapturedPicture) => void;
190  // TODO(Bacon): Is it possible to implement this in the browser?
191  /**
192   * If set to `true`, camera skips orientation adjustment and returns an image straight from the device's camera.
193   * If enabled, `quality` option is discarded (processing pipeline is skipped as a whole).
194   * Although enabling this option reduces image delivery time significantly, it may cause the image to appear in a wrong orientation
195   * in the `Image` component (at the time of writing, it does not respect EXIF orientation of the images).
196   * > **Note**: Enabling `skipProcessing` would cause orientation uncertainty. `Image` component does not respect EXIF
197   * > stored orientation information, that means obtained image would be displayed wrongly (rotated by 90°, 180° or 270°).
198   * > Different devices provide different orientations. For example some Sony Xperia or Samsung devices don't provide
199   * > correctly oriented images by default. To always obtain correctly oriented image disable `skipProcessing` option.
200   */
201  skipProcessing?: boolean;
202  /**
203   * @platform web
204   */
205  scale?: number;
206  /**
207   * @platform web
208   */
209  imageType?: ImageType;
210  /**
211   * @platform web
212   */
213  isImageMirror?: boolean;
214  /**
215   * @hidden
216   */
217  id?: number;
218  /**
219   * @hidden
220   */
221  fastMode?: boolean;
222  /**
223   * @hidden
224   */
225  maxDownsampling?: number;
226};
227
228// @needsAudit
229export type CameraRecordingOptions = {
230  /**
231   * Maximum video duration in seconds.
232   */
233  maxDuration?: number;
234  /**
235   * Maximum video file size in bytes.
236   */
237  maxFileSize?: number;
238  /**
239   * Specify the quality of recorded video. Use one of [`VideoQuality.<value>`](#videoquality).
240   * Possible values: for 16:9 resolution `2160p`, `1080p`, `720p`, `480p` : `Android only` and for 4:3 `4:3` (the size is 640x480).
241   * If the chosen quality is not available for a device, the highest available is chosen.
242   */
243  quality?: number | string;
244  /**
245   * If present, video will be recorded with no sound.
246   */
247  mute?: boolean;
248  /**
249   * If `true`, the recorded video will be flipped along the vertical axis. iOS flips videos recorded with the front camera by default,
250   * but you can reverse that back by setting this to `true`. On Android, this is handled in the user's device settings.
251   * @platform ios
252   */
253  mirror?: boolean;
254  /**
255   * Only works if `useCamera2Api` is set to `true`. This option specifies a desired video bitrate. For example, `5*1000*1000` would be 5Mbps.
256   * @platform android
257   */
258  videoBitrate?: number;
259  /**
260   * This option specifies what codec to use when recording the video. See [`VideoCodec`](#videocodec) for the possible values.
261   * @platform ios
262   */
263  codec?: VideoCodec;
264};
265
266/**
267 * @hidden
268 */
269export type PictureSavedListener = (event: {
270  nativeEvent: { data: CameraCapturedPicture; id: number };
271}) => void;
272
273/**
274 * @hidden
275 */
276export type CameraReadyListener = () => void;
277
278/**
279 * @hidden
280 */
281export type MountErrorListener = (event: { nativeEvent: CameraMountError }) => void;
282
283// @docsMissing
284export type CameraMountError = { message: string };
285
286// @docsMissing
287export type Point = {
288  x: number;
289  y: number;
290};
291
292export type BarCodeSize = {
293  /**
294   * The height value.
295   */
296  height: number;
297  /**
298   * The width value.
299   */
300  width: number;
301};
302
303/**
304 * These coordinates are represented in the coordinate space of the camera source (e.g. when you
305 * are using the camera view, these values are adjusted to the dimensions of the view).
306 */
307export type BarCodePoint = Point;
308
309export type BarCodeBounds = {
310  /**
311   * The origin point of the bounding box.
312   */
313  origin: BarCodePoint;
314  /**
315   * The size of the bounding box.
316   */
317  size: BarCodeSize;
318};
319
320// @needsAudit
321export type BarCodeScanningResult = {
322  /**
323   * The barcode type.
324   */
325  type: string;
326  /**
327   * The information encoded in the bar code.
328   */
329  data: string;
330  /**
331   * Corner points of the bounding box.
332   * `cornerPoints` is not always available and may be empty. On iOS, for `code39` and `pdf417`
333   * you don't get this value.
334   */
335  cornerPoints: BarCodePoint[];
336  /**
337   * The [BarCodeBounds](#barcodebounds) object.
338   * `bounds` in some case will be representing an empty rectangle.
339   * Moreover, `bounds` doesn't have to bound the whole barcode.
340   * For some types, they will represent the area used by the scanner.
341   */
342  bounds: BarCodeBounds;
343};
344
345export type FaceDetectionResult = {
346  /**
347   * Array of objects representing results of face detection.
348   * See [`FaceFeature`](facedetector/#facefeature) in FaceDetector documentation for more details.
349   */
350  faces: object[];
351};
352
353/**
354 * @hidden
355 */
356export type ConstantsType = {
357  Type: CameraType;
358  FlashMode: FlashMode;
359  AutoFocus: AutoFocus;
360  WhiteBalance: WhiteBalance;
361  VideoQuality: VideoQuality;
362  VideoStabilization: VideoStabilization;
363  VideoCodec: VideoCodec;
364};
365
366// @needsAudit
367export type CameraProps = ViewProps & {
368  /**
369   * Camera facing. Use one of `CameraType`. When `CameraType.front`, use the front-facing camera.
370   * When `CameraType.back`, use the back-facing camera.
371   * @default CameraType.back
372   */
373  type?: number | CameraType;
374  /**
375   * Camera flash mode. Use one of [`FlashMode.<value>`](#flashmode-1). When `FlashMode.on`, the flash on your device will
376   * turn on when taking a picture, when `FlashMode.off`, it won't. Setting to `FlashMode.auto` will fire flash if required,
377   * `FlashMode.torch` turns on flash during the preview.
378   * @default FlashMode.off
379   */
380  flashMode?: number | FlashMode;
381  /**
382   * Camera white balance. Use one of [`WhiteBalance.<value>`](#whitebalance). If a device does not support any of these values previous one is used.
383   * @default WhiteBalance.auto
384   */
385  whiteBalance?: number | WhiteBalance;
386  /**
387   * State of camera auto focus. Use one of [`AutoFocus.<value>`](#autofocus-1). When `AutoFocus.on`,
388   * auto focus will be enabled, when `AutoFocus.off`, it won't and focus will lock as it was in the moment of change,
389   * but it can be adjusted on some devices via `focusDepth` prop.
390   * @default AutoFocus.on
391   */
392  autoFocus?: boolean | number | AutoFocus;
393  /**
394   * A value between `0` and `1` being a percentage of device's max zoom. `0` - not zoomed, `1` - maximum zoom.
395   * @default 0
396   */
397  zoom?: number;
398  /**
399   * A string representing aspect ratio of the preview, eg. `4:3`, `16:9`, `1:1`. To check if a ratio is supported
400   * by the device use [`getSupportedRatiosAsync`](#getsupportedratiosasync).
401   * @default 4:3
402   * @platform android
403   */
404  ratio?: string;
405  /**
406   * Distance to plane of the sharpest focus. A value between `0` and `1` where: `0` - infinity focus, `1` - focus as close as possible.
407   * For Android this is available only for some devices and when `useCamera2Api` is set to `true`.
408   * @default 0
409   */
410  focusDepth?: number;
411  /**
412   * Callback invoked when camera preview has been set.
413   */
414  onCameraReady?: () => void;
415  /**
416   * Whether to use Android's Camera2 API. See `Note` at the top of this page.
417   * @platform android
418   */
419  useCamera2Api?: boolean;
420  /**
421   * A string representing the size of pictures [`takePictureAsync`](#takepictureasync) will take.
422   * Available sizes can be fetched with [`getAvailablePictureSizesAsync`](#getavailablepicturesizesasync).
423   */
424  pictureSize?: string;
425  /**
426   * The video stabilization mode used for a video recording. Use one of [`VideoStabilization.<value>`](#videostabilization).
427   * You can read more about each stabilization type in [Apple Documentation](https://developer.apple.com/documentation/avfoundation/avcapturevideostabilizationmode).
428   * @platform ios
429   */
430  videoStabilizationMode?: VideoStabilization;
431  /**
432   * Callback invoked when camera preview could not been started.
433   * @param event Error object that contains a `message`.
434   */
435  onMountError?: (event: CameraMountError) => void;
436  /**
437   * Settings exposed by [`BarCodeScanner`](bar-code-scanner) module. Supported settings: **barCodeTypes**.
438   * @example
439   * ```tsx
440   * <Camera
441   *   barCodeScannerSettings={{
442   *     barCodeTypes: [BarCodeScanner.Constants.BarCodeType.qr],
443   *   }}
444   * />
445   * ```
446   */
447  barCodeScannerSettings?: BarCodeSettings;
448  /**
449   * Callback that is invoked when a bar code has been successfully scanned. The callback is provided with
450   * an object of the [`BarCodeScanningResult`](#barcodescanningresult) shape, where the `type`
451   * refers to the bar code type that was scanned and the `data` is the information encoded in the bar code
452   * (in this case of QR codes, this is often a URL). See [`BarCodeScanner.Constants.BarCodeType`](bar-code-scanner#supported-formats)
453   * for supported values.
454   * @param scanningResult
455   */
456  onBarCodeScanned?: (scanningResult: BarCodeScanningResult) => void;
457  /**
458   * A settings object passed directly to an underlying module providing face detection features.
459   * See [`DetectionOptions`](facedetector/#detectionoptions) in FaceDetector documentation for details.
460   */
461  faceDetectorSettings?: object;
462  /**
463   * Callback invoked with results of face detection on the preview.
464   * See [`DetectionResult`](facedetector/#detectionresult) in FaceDetector documentation for more details.
465   * @param faces
466   */
467  onFacesDetected?: (faces: FaceDetectionResult) => void;
468  /**
469   * A URL for an image to be shown while the camera is loading.
470   * @platform web
471   */
472  poster?: string;
473};
474
475/**
476 * @hidden
477 */
478export type CameraNativeProps = {
479  pointerEvents?: any;
480  style?: any;
481  ref?: Function;
482  onCameraReady?: CameraReadyListener;
483  onMountError?: MountErrorListener;
484  onBarCodeScanned?: (event: { nativeEvent: BarCodeScanningResult }) => void;
485  onFacesDetected?: (event: { nativeEvent: FaceDetectionResult }) => void;
486  onFaceDetectionError?: (event: { nativeEvent: Error }) => void;
487  onPictureSaved?: PictureSavedListener;
488  type?: number | string;
489  flashMode?: number | string;
490  autoFocus?: string | boolean | number;
491  focusDepth?: number;
492  zoom?: number;
493  whiteBalance?: number | string;
494  pictureSize?: string;
495  barCodeScannerSettings?: BarCodeSettings;
496  faceDetectorSettings?: object;
497  barCodeScannerEnabled?: boolean;
498  faceDetectorEnabled?: boolean;
499  ratio?: string;
500  useCamera2Api?: boolean;
501  poster?: string;
502};
503
504// @docsMissing
505export type BarCodeSettings = {
506  barCodeTypes: string[];
507  interval?: number;
508};
509
510export { PermissionResponse, PermissionStatus, PermissionExpiration, PermissionHookOptions };
511