Skip to content

Commit a54dc4f

Browse files
authored
Merge pull request #223 from nabati/pn/add-specific-document-types
Add support for specifying single or multiple document types
2 parents cffcdab + 6b0827f commit a54dc4f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

__tests__/typescript/index.test.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import DocumentPicker from "react-native-document-picker";
22

33
// Option is correct about pick
4-
54
DocumentPicker.pick({
65
type: [DocumentPicker.types.allFiles]
76
})
@@ -64,6 +63,13 @@ DocumentPicker.pickMultiple({
6463
type: [DocumentPicker.types.video,DocumentPicker.types.pdf, 'public.audio']
6564
})
6665

66+
DocumentPicker.pick({type: 'image/jpg'});
67+
DocumentPicker.pick({type: 'public.png'});
68+
69+
DocumentPicker.pick({type: ['image/jpg', 'image/jpeg', 'image/png', 'application/pdf']});
70+
DocumentPicker.pick({type: ['public.png', 'public.jpeg']});
71+
72+
6773
try {
6874
throw new Error('test')
6975
} catch (e) {
@@ -72,4 +78,4 @@ try {
7278
} else {
7379

7480
}
75-
}
81+
}

index.d.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
declare module 'react-native-document-picker' {
2+
type UTI = 'public.png' | 'public.jpeg' | 'com.adobe.pdf';
3+
type MimeType = 'image/jpg' | 'image/jpeg' | 'image/png' | 'application/pdf';
4+
type Extension = '.jpeg' | '.jpg' | '.png' | '.txt' | '.pdf';
5+
6+
type DocumentType = {
7+
android: MimeType | MimeType[]
8+
ios: UTI | UTI[]
9+
windows: Extension | Extension[]
10+
};
11+
212
type Types = {
313
mimeTypes: {
414
allFiles: '*/*',
@@ -32,7 +42,7 @@ declare module 'react-native-document-picker' {
3242
windows: Types['extensions']
3343
};
3444
interface DocumentPickerOptions<OS extends keyof PlatformTypes> {
35-
type: Array<PlatformTypes[OS][keyof PlatformTypes[OS]]>
45+
type: Array<PlatformTypes[OS][keyof PlatformTypes[OS]]> | DocumentType[OS]
3646
}
3747
interface DocumentPickerResponse {
3848
uri: string;

0 commit comments

Comments
 (0)