forked from ivpusic/react-native-image-crop-picker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
512 lines (441 loc) · 13.3 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
declare module "react-native-image-crop-picker" {
/**
* AVAssetExportPreset presets.
*
* @see https://developer.apple.com/documentation/avfoundation/avassetexportsession/export_preset_names_for_quicktime_files_of_a_given_size
*/
type CompressVideoPresets =
| '640x480'
| '960x540'
| '1280x720'
| '1920x1080'
| 'HEVC3840x2160'
| 'LowQuality'
| 'MediumQuality'
| 'HighestQuality'
| 'Passthrough';
/**
* iOS smart album types
*
* @see https://developer.apple.com/documentation/photokit/phassetcollectionsubtype
*/
type SmartAlbums =
| 'Regular'
| 'SyncedEvent'
| 'SyncedFaces'
| 'SyncedAlbum'
| 'Imported'
| 'PhotoStream'
| 'CloudShared'
| 'Generic'
| 'Panoramas'
| 'Videos'
| 'Favorites'
| 'Timelapses'
| 'AllHidden'
| 'RecentlyAdded'
| 'Bursts'
| 'SlomoVideos'
| 'UserLibrary'
| 'Screenshots'
| 'SelfPortraits'
/** >= iOS 10.2 */
| 'DepthEffect'
/** >= iOS 10.3 */
| 'LivePhotos'
/** >= iOS 11 */
| 'Animated'
| 'LongExposure';
export interface CommonOptions {
/**
* Enable or disable multiple image selection.
*
* @default false
*/
multiple?: boolean;
/**
* Min number of files to select when using `multiple` option.
*
* @platform iOS only
* @default 1
*/
minFiles?: number;
/**
* Max number of files to select when using `multiple` option.
*
* @platform iOS only
* @default 5
*/
maxFiles?: number;
/**
* Promise will resolve/reject once ViewController completion block is called.
*
* @platform iOS only
* @default true
*/
waitAnimationEnd?: boolean;
/**
* List of smart albums to choose from.
*
* @platform iOS only
* @default ['UserLibrary', 'PhotoStream', 'Panoramas', 'Videos', 'Bursts']
*/
smartAlbums?: SmartAlbums[];
/**
* Whether to default to the front camera when opened. Please note that not all
* Android devices handle this parameter, see
* [issue #1058](https://github.com/ivpusic/react-native-image-crop-picker/issues/1058).
*
* @default false
*/
useFrontCamera?: boolean;
/**
* Text displayed while photo is loading in picker.
*
* @default 'Processing assets...'
*/
loadingLabelText?: string;
/**
* Whether to show the number of selected assets.
*
* @default true
*/
showsSelectedCount?: boolean;
/**
* Applies a sort order on the creation date on how media is displayed within the
* albums/detail photo views when opening the image picker.
*
* @platform iOS only
* @default 'none'
*/
sortOrder?: 'none' | 'asc' | 'desc';
/**
* Whether to display bottom controls.
*
* @platform Android only
* @default false
*/
hideBottomControls?: boolean;
/**
* When set to false, does not write temporary files for the selected images. This is useful
* to improve performance when you are retrieving file contents with the includeBase64 option
* and don't need to read files from disk.
*
* @platform iOS only
* @default true
*/
writeTempFile?: boolean;
}
type ImageOptions = CommonOptions & {
mediaType: 'photo';
/**
* Width of result image when used with `cropping` option.
*/
width?: number;
/**
* Height of result image when used with `cropping` option.
*/
height?: number;
/**
* When set to true, the image file content will be available as a base64-encoded string in
* the data property. Hint: To use this string as an image source, use it like:
* <Image source={{uri: `data:${image.mime};base64,${image.data}`}} />
*
* @default false
*/
includeBase64?: boolean;
/**
* Include image exif data in the response.
*
* @default false
*/
includeExif?: boolean;
/**
* Whether to convert photos to JPG. This will also convert any Live Photo into its JPG representation.
*
* @default false
*/
forceJpg?: boolean;
/**
* Enable or disable cropping.
*
* @default false
*/
cropping?: boolean;
/**
* When set to true, the image will always fill the mask space.
*
* @default true
*/
avoidEmptySpaceAroundImage?: boolean;
/**
* When cropping image, determines ActiveWidget color.
*
* @platform Android only
* @default '#424242'
*/
cropperActiveWidgetColor?: string;
/**
* When cropping image, determines the color of StatusBar.
*
* @platform Android only
* @default '#424242'
*/
cropperStatusBarColor?: string;
/**
* When cropping image, determines the color of Toolbar.
*
* @platform Android only
* @default '#424242'
*/
cropperToolbarColor?: string;
/**
* When cropping image, determines the color of Toolbar text and buttons.
*
* @platform Android only
* @default 'darker orange'
*/
cropperToolbarWidgetColor?: string;
/**
* When cropping image, determines the title of Toolbar.
*
* @default 'Edit Photo'
*/
cropperToolbarTitle?: string;
/**
* Enables user to apply custom rectangle area for cropping.
*
* @platform iOS only
* @default false
*/
freeStyleCropEnabled?: boolean;
/**
* cropperTintColor
*/
cropperTintColor?: string;
/**
* Enable or disable circular cropping mask.
*
* @default false
*/
cropperCircleOverlay?: boolean;
/**
* Cancel button text.
*
* @default 'Cancel'
*/
cropperCancelText?: string;
/**
* Cancel button color. HEX-like string color.
*
* @example '#ff00ee'
* @platform iOS only
*/
cropperCancelColor?: string;
/**
* Choose button text.
*
* @default 'Choose'
*/
cropperChooseText?: string;
/**
* Choose button color. HEX-like string color.
*
* @example '#EE00DD'
* @platform iOS only
*/
cropperChooseColor?: string;
/**
* Enable or disable cropper rotate buttons.
*
* @platform iOS only
* @default false
*/
cropperRotateButtonsHidden?: boolean
/**
* Whether to show the 3x3 grid on top of the image during cropping.
*
* @platform Android only
* @default true
*/
showCropGuidelines?: boolean;
/**
* Whether to show the square crop frame during cropping
*
* @platform Android only
* @default true
*/
showCropFrame?: boolean;
/**
* Whether to enable rotating the image by hand gesture.
*
* @platform Android only
* @default false
*/
enableRotationGesture?: boolean;
/**
* When cropping image, disables the color setters for cropping library.
*
* @platform Android only
* @default false
*/
disableCropperColorSetters?: boolean;
/**
* Compress image with maximum width.
*
* @default null
*/
compressImageMaxWidth?: number;
/**
* Compress image with maximum height.
*
* @default null
*/
compressImageMaxHeight?: number;
/**
* Compress image with quality (from 0 to 1, where 1 is best quality). On iOS, values larger
* than 0.8 don't produce a noticeable quality increase in most images, while a value of 0.8
* will reduce the file size by about half or less compared to a value of 1.
*
* @default Android: 1, iOS: 0.8
*/
compressImageQuality?: number;
}
type CropperOptions = ImageOptions & {
/**
* Selected image location
*/
path: string;
}
type VideoOptions = CommonOptions & {
mediaType: 'video';
/**
* Choose which preset will be used for video compression.
*
* @platform iOS only
* @default 'MediumQuality'
*/
compressVideoPreset?: CompressVideoPresets;
};
type AnyOptions = Omit<ImageOptions, 'mediaType'> & Omit<VideoOptions, 'mediaType'> & {
mediaType?: 'any';
};
export type Options = AnyOptions | VideoOptions | ImageOptions;
interface ImageVideoCommon {
/**
* Selected image location. This is null when the `writeTempFile` option is set to `false`.
*/
path: string;
/**
* Selected image size in bytes.
*/
size: number;
/**
* Selected image/video width.
*/
width: number;
/**
* Selected image/video height.
*/
height: number;
/**
* Selected image MIME type (image/jpeg, image/png, etc).
*/
mime: string;
/**
* Extracted exif data from image. Response format is platform specific.
*/
exif?: any;
/**
* Selected image's localidentifier, used for PHAsset searching.
*
* @platform iOS only
*/
localIdentifier?: string;
/**
* Selected image's source path, do not have write access.
*
* @platform iOS only
*/
sourceURL?: string;
/**
* Selected image/video's filename.
*
* @platform iOS only
*/
filename?: string;
/**
* UNIX timestamp when image was created.
*
* @platform iOS only
*/
creationDate?: string;
/**
* UNIX timestamp when image was last modified.
*/
modificationDate?: string;
}
export interface Image extends ImageVideoCommon {
/**
* Optional base64 selected file representation.
*/
data?: string | null;
/**
* Cropped image rectangle (width, height, x, y).
*/
cropRect?: CropRect | null;
}
export interface Video extends ImageVideoCommon {
/**
* Video duration in milliseconds
*/
duration: number | null;
}
export type ImageOrVideo = Image | Video;
export interface CropRect {
x: number;
y: number;
width: number;
height: number;
}
type PickerErrorCodeCommon =
| 'E_PICKER_CANCELLED'
| 'E_NO_IMAGE_DATA_FOUND'
| 'E_NO_LIBRARY_PERMISSION'
| 'E_NO_CAMERA_PERMISSION'
| 'E_ERROR_WHILE_CLEANING_FILES';
type PickerErrorCodeIOS =
| 'E_PICKER_CANNOT_RUN_CAMERA_ON_SIMULATOR'
| 'E_CROPPER_IMAGE_NOT_FOUND'
| 'E_CANNOT_SAVE_IMAGE'
| 'E_CANNOT_PROCESS_VIDEO';
type PickerErrorCodeAndroid =
| 'E_ACTIVITY_DOES_NOT_EXIST'
| 'E_CALLBACK_ERROR'
| 'E_FAILED_TO_SHOW_PICKER'
| 'E_FAILED_TO_OPEN_CAMERA'
| 'E_CAMERA_IS_NOT_AVAILABLE'
| 'E_CANNOT_LAUNCH_CAMERA';
export type PickerErrorCode = PickerErrorCodeCommon | PickerErrorCodeIOS | PickerErrorCodeAndroid;
/** Change return type based on `multiple` property. */
export type PossibleArray<O, T> = O extends { multiple: true; } ? T[] : T;
/** Isolate return type based on `mediaType` property. */
type MediaType<O> =
O extends { mediaType: 'photo'; } ? Image :
O extends { mediaType: 'video'; } ? Video :
ImageOrVideo;
export function openPicker<O extends Options>(options: O): Promise<PossibleArray<O, MediaType<O>>>;
export function openCamera<O extends Options>(options: O): Promise<PossibleArray<O, MediaType<O>>>;
export function openCropper(options: CropperOptions): Promise<Image>;
export function clean(): Promise<void>;
export function cleanSingle(path: string): Promise<void>;
export interface ImageCropPicker {
openPicker<O extends Options>(options: O): Promise<PossibleArray<O, MediaType<O>>>;
openCamera<O extends Options>(options: O): Promise<PossibleArray<O, MediaType<O>>>;
openCropper(options: CropperOptions): Promise<Image>;
clean(): Promise<void>;
cleanSingle(path: string): Promise<void>;
}
const ImageCropPicker: ImageCropPicker;
export default ImageCropPicker;
}