From a0c7a8f4b591c864c8025d0eb2360b8270311301 Mon Sep 17 00:00:00 2001 From: dburdan Date: Sat, 4 Jul 2020 14:36:08 -0700 Subject: [PATCH] Add types for smart albums, compressed video presets, and picker errors (#1332) * Added picker error code types * Added types for CompressVideoPresets and iOS SmartAlbums --- README.md | 1 + index.d.ts | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2cecc53..a7bdf2f 100644 --- a/README.md +++ b/README.md @@ -154,6 +154,7 @@ ImagePicker.clean().then(() => { #### Smart Album Types (ios) +NOTE: Some of these types may not be available on all iOS versions. Be sure to check this to avoid issues. ``` ['PhotoStream', 'Generic', 'Panoramas', 'Videos', 'Favorites', 'Timelapses', 'AllHidden', 'RecentlyAdded', 'Bursts', 'SlomoVideos', 'UserLibrary', 'SelfPortraits', 'Screenshots', 'DepthEffect', 'LivePhotos', 'Animated', 'LongExposure'] ``` diff --git a/index.d.ts b/index.d.ts index f3e44c7..f5571a7 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,4 +1,53 @@ 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 Options { cropping?: boolean; width?: number; @@ -19,9 +68,9 @@ declare module "react-native-image-crop-picker" { disableCropperColorSetters?: boolean; maxFiles?: number; waitAnimationEnd?: boolean; - smartAlbums?: string[]; + smartAlbums?: SmartAlbums[]; useFrontCamera?: boolean; - compressVideoPreset?: string; + compressVideoPreset?: CompressVideoPresets; compressImageMaxWidth?: number; compressImageMaxHeight?: number; compressImageQuality?: number; @@ -60,6 +109,29 @@ declare module "react-native-image-crop-picker" { height: number; } + type PickerErrorCodeCommon = + | 'E_PICKER_CANCELLED' + | 'E_NO_IMAGE_DATA_FOUND' + | 'E_PERMISSION_MISSING' + | 'E_ERROR_WHILE_CLEANING_FILES'; + + type PickerErrorCodeIOS = + | 'E_PICKER_CANNOT_RUN_CAMERA_ON_SIMULATOR' + | 'E_PICKER_NO_CAMERA_PERMISSION' + | '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; + export function openPicker(options: Options): Promise; export function openCamera(options: Options): Promise; export function openCropper(options: Options): Promise;