11import { NativeModules , Image } from 'react-native' ;
22
3+ export enum MediaType {
4+ VIDEO = 'video' ,
5+ IMAGE = 'image' ,
6+ ALL = 'all' ,
7+ }
8+
39export type Results = {
410 path : string ;
511 fileName : string ;
612 localIdentifier : string ;
713 width : number ;
814 height : number ;
915 mime : string ;
10- type : string ;
1116 size : number ;
1217 bucketId ?: number ;
1318 realPath ?: string ;
1419 parentFolderName ?: string ;
15- thumbnail ?: string ;
1620 creationDate ?: string ;
1721} ;
1822
23+ export interface VideoResults extends Results {
24+ type : MediaType . VIDEO ;
25+ thumbnail ?: string ;
26+ }
27+
28+ export interface ImageResults extends Results {
29+ type : MediaType . IMAGE ;
30+ thumbnail ?: undefined ;
31+ }
32+
1933export type PickerErrorCode =
2034 | 'PICKER_CANCELLED'
2135 | 'NO_LIBRARY_PERMISSION'
2236 | 'NO_CAMERA_PERMISSION' ;
2337
24- export type Options = {
38+ export type Options < T extends MediaType = MediaType . ALL > = {
39+ mediaType ?: T ;
2540 isPreview ?: boolean ;
2641 selectedColor ?: string ;
27- selectedAssets ?: Results [ ] ;
2842 tapHereToChange ?: string ;
2943 cancelTitle ?: string ;
3044 doneTitle ?: string ;
@@ -44,12 +58,10 @@ export type Options = {
4458 autoPlay ?: boolean ;
4559 muteAudio ?: boolean ;
4660 preventAutomaticLimitedAccessAlert ?: boolean ; // newest iOS 14
47- mediaType ?: string ;
4861 numberOfColumn ?: number ;
4962 maxSelectedAssets ?: number ;
5063 fetchOption ?: Object ;
5164 fetchCollectionOption ?: Object ;
52- singleSelectedMode ?: boolean ;
5365 maximumMessageTitle ?: string ;
5466 maximumMessage ?: string ;
5567 messageTitleButton ?: string ;
@@ -59,8 +71,34 @@ export type Options = {
5971 haveThumbnail ?: boolean ;
6072} ;
6173
74+ export interface SinglePickerOptions {
75+ selectedAssets ?: Results ;
76+ singleSelectedMode : true ;
77+ }
78+
79+ export interface MultiPickerOptions {
80+ selectedAssets ?: Results [ ] ;
81+ singleSelectedMode ?: false ;
82+ }
83+
84+ interface MediaTypeOptions {
85+ [ MediaType . VIDEO ] : { isExportThumbnail ?: boolean } ;
86+ [ MediaType . ALL ] : MediaTypeOptions [ MediaType . VIDEO ] ;
87+ }
88+
89+ interface MediaTypeResults {
90+ [ MediaType . IMAGE ] : ImageResults ;
91+ [ MediaType . VIDEO ] : VideoResults ;
92+ [ MediaType . ALL ] : ImageResults | VideoResults ;
93+ }
94+
6295type MultipleImagePickerType = {
63- openPicker ( options : Options ) : Promise < Results [ ] > ;
96+ openPicker < T extends MediaType = MediaType . ALL > (
97+ options : MultiPickerOptions & MediaTypeOptions [ T ] & Options < T >
98+ ) : Promise < MediaTypeResults [ T ] [ ] > ;
99+ openPicker < T extends MediaType = MediaType . ALL > (
100+ options : SinglePickerOptions & MediaTypeOptions [ T ] & Options < T >
101+ ) : Promise < MediaTypeResults [ T ] > ;
64102} ;
65103
66104const { MultipleImagePicker } = NativeModules ;
0 commit comments