1
1
import { Platform , ModalPropsIOS } from 'react-native'
2
2
import invariant from 'invariant'
3
- import type { PlatformTypes , SupportedPlatforms } from './fileTypes'
3
+ import type { PlatformTypes } from './fileTypes'
4
4
import { perPlatformTypes } from './fileTypes'
5
5
import { NativeDocumentPicker } from './NativeDocumentPicker'
6
6
@@ -21,19 +21,16 @@ export type DirectoryPickerResponse = {
21
21
22
22
export type TransitionStyle = 'coverVertical' | 'flipHorizontal' | 'crossDissolve' | 'partialCurl'
23
23
24
- export type DocumentPickerOptions < OS extends SupportedPlatforms > = {
25
- type ?:
26
- | string
27
- | PlatformTypes [ OS ] [ keyof PlatformTypes [ OS ] ]
28
- | Array < PlatformTypes [ OS ] [ keyof PlatformTypes [ OS ] ] | string >
24
+ export type DocumentPickerOptions = {
25
+ type ?: string | Array < PlatformTypes | string >
29
26
mode ?: 'import' | 'open'
30
27
copyTo ?: 'cachesDirectory' | 'documentDirectory'
31
28
allowMultiSelection ?: boolean
32
29
transitionStyle ?: TransitionStyle
33
30
} & Pick < ModalPropsIOS , 'presentationStyle' >
34
31
35
- export async function pickDirectory < OS extends SupportedPlatforms > (
36
- params ?: Pick < DocumentPickerOptions < OS > , 'presentationStyle' | 'transitionStyle' > ,
32
+ export async function pickDirectory (
33
+ params ?: Pick < DocumentPickerOptions , 'presentationStyle' | 'transitionStyle' > ,
37
34
) : Promise < DirectoryPickerResponse | null > {
38
35
if ( Platform . OS === 'ios' ) {
39
36
const result = await pick ( {
@@ -48,27 +45,23 @@ export async function pickDirectory<OS extends SupportedPlatforms>(
48
45
}
49
46
}
50
47
51
- export function pickSingle < OS extends SupportedPlatforms > (
52
- opts ?: DocumentPickerOptions < OS > ,
53
- ) : Promise < DocumentPickerResponse > {
48
+ export function pickSingle ( opts ?: DocumentPickerOptions ) : Promise < DocumentPickerResponse > {
54
49
const options = {
55
50
...opts ,
56
51
allowMultiSelection : false ,
57
52
}
58
53
return pick ( options ) . then ( ( results ) => results [ 0 ] )
59
54
}
60
55
61
- export function pick < OS extends SupportedPlatforms > (
62
- opts ?: DocumentPickerOptions < OS > ,
63
- ) : Promise < DocumentPickerResponse [ ] > {
56
+ export function pick ( opts ?: DocumentPickerOptions ) : Promise < DocumentPickerResponse [ ] > {
64
57
const options = {
65
58
// must be false to maintain old (v5) behavior
66
59
allowMultiSelection : false ,
67
60
type : [ types . allFiles ] ,
68
61
...opts ,
69
62
}
70
63
71
- const newOpts : DoPickParams < OS > = {
64
+ const newOpts : DoPickParams = {
72
65
presentationStyle : 'formSheet' ,
73
66
transitionStyle : 'coverVertical' ,
74
67
...options ,
@@ -78,16 +71,14 @@ export function pick<OS extends SupportedPlatforms>(
78
71
return doPick ( newOpts )
79
72
}
80
73
81
- type DoPickParams < OS extends SupportedPlatforms > = DocumentPickerOptions < OS > & {
82
- type : Array < PlatformTypes [ OS ] [ keyof PlatformTypes [ OS ] ] | string >
74
+ type DoPickParams = DocumentPickerOptions & {
75
+ type : Array < PlatformTypes | string >
83
76
allowMultiSelection : boolean
84
77
presentationStyle : NonNullable < ModalPropsIOS [ 'presentationStyle' ] >
85
78
transitionStyle : TransitionStyle
86
79
}
87
80
88
- function doPick < OS extends SupportedPlatforms > (
89
- options : DoPickParams < OS > ,
90
- ) : Promise < DocumentPickerResponse [ ] > {
81
+ function doPick ( options : DoPickParams ) : Promise < DocumentPickerResponse [ ] > {
91
82
invariant (
92
83
! ( 'filetype' in options ) ,
93
84
'A `filetype` option was passed to DocumentPicker.pick, the correct option is `type`' ,
0 commit comments