|
1 | 1 | declare module 'react-native-document-picker' {
|
2 |
| - interface DocumentPickerOptions { |
3 |
| - filetype: Array<string>; |
4 |
| - multiple?: Boolean; |
| 2 | + type Types = { |
| 3 | + mimeTypes: { |
| 4 | + allFiles: '*/*', |
| 5 | + audio: 'audio/*', |
| 6 | + images: 'image/*', |
| 7 | + plainText: 'text/plain', |
| 8 | + pdf: 'application/pdf', |
| 9 | + video: 'video/*', |
| 10 | + }, |
| 11 | + utis: { |
| 12 | + allFiles: 'public.content', |
| 13 | + audio: 'public.audio', |
| 14 | + images: 'public.image', |
| 15 | + plainText: 'public.plain-text', |
| 16 | + pdf: 'com.adobe.pdf', |
| 17 | + video: 'public.movie', |
| 18 | + }, |
| 19 | + extensions: { |
| 20 | + allFiles: '*', |
| 21 | + audio: |
| 22 | + '.3g2 .3gp .aac .adt .adts .aif .aifc .aiff .asf .au .m3u .m4a .m4b .mid .midi .mp2 .mp3 .mp4 .rmi .snd .wav .wax .wma', |
| 23 | + images: '.jpeg .jpg .png', |
| 24 | + plainText: '.txt', |
| 25 | + pdf: '.pdf', |
| 26 | + video: '.mp4', |
| 27 | + }, |
| 28 | + }; |
| 29 | + type PlatformTypes = { |
| 30 | + android: Types['mimeTypes'] |
| 31 | + ios: Types['utis'] |
| 32 | + windows: Types['extensions'] |
| 33 | + }; |
| 34 | + interface DocumentPickerOptions<OS extends keyof PlatformTypes> { |
| 35 | + type: Array<PlatformTypes[OS][keyof PlatformTypes[OS]]> |
5 | 36 | }
|
6 | 37 | interface DocumentPickerResponse {
|
7 | 38 | uri: string;
|
8 | 39 | type: string;
|
9 | 40 | fileName: string;
|
10 | 41 | fileSize: string;
|
11 | 42 | }
|
12 |
| - export class DocumentPicker { |
13 |
| - static pick( |
14 |
| - options: { multiple: false } & DocumentPickerOptions |
| 43 | + type Platform = 'ios' | 'android' | 'windows' |
| 44 | + export class DocumentPicker<OS extends keyof PlatformTypes = Platform> { |
| 45 | + static types: PlatformTypes['ios'] | PlatformTypes['android'] | PlatformTypes['windows'] |
| 46 | + static pick<OS extends keyof PlatformTypes = Platform>( |
| 47 | + options: DocumentPickerOptions<OS> |
15 | 48 | ): Promise<DocumentPickerResponse>;
|
16 |
| - static pickMultiple( |
17 |
| - options: { multiple: true } & DocumentPickerOptions |
| 49 | + static pickMultiple<OS extends keyof PlatformTypes = Platform>( |
| 50 | + options: DocumentPickerOptions<OS> |
18 | 51 | ): Promise<DocumentPickerResponse>;
|
19 | 52 | static isCancel(err: any): void;
|
20 | 53 | }
|
|
0 commit comments