@@ -13,7 +13,7 @@ async function openDocumentByOldDocumentPicker(
13
13
documentPickerModule : typeof OldDocumentPicker ,
14
14
options ?: OpenDocumentOptions ,
15
15
) : Promise < FilePickerResponse > {
16
- Logger . log ( 'called openDocumentByOldDocumentPicker ') ;
16
+ Logger . warn ( 'please update to @react-native-documents/picker ') ;
17
17
try {
18
18
const { uri, size, name, type } = await documentPickerModule . pickSingle ( ) ;
19
19
return normalizeFile ( { uri, size, name, type } ) ;
@@ -29,7 +29,6 @@ async function openDocumentByNewDocumentsPicker(
29
29
documentPickerModule : typeof NewDocumentsPicker ,
30
30
options ?: OpenDocumentOptions ,
31
31
) : Promise < FilePickerResponse > {
32
- Logger . log ( 'called openDocumentByNewDocumentsPicker' ) ;
33
32
try {
34
33
const results = await documentPickerModule . pick ( ) ;
35
34
const { uri, size, name, type } = results [ 0 ] ;
@@ -45,29 +44,16 @@ async function openDocumentByNewDocumentsPicker(
45
44
}
46
45
}
47
46
47
+ function isOldModule ( documentPicker : DocumentPicker ) : documentPicker is typeof OldDocumentPicker {
48
+ return typeof ( documentPicker as typeof OldDocumentPicker ) . pickSingle === 'function' ;
49
+ }
50
+
48
51
export async function openDocument (
49
52
documentPickerModule : DocumentPicker ,
50
53
options ?: OpenDocumentOptions ,
51
54
) : Promise < FilePickerResponse > {
52
- let oldDocumentPicker : typeof OldDocumentPicker | undefined ;
53
- let newDocumentsPicker : typeof NewDocumentsPicker | undefined ;
54
-
55
- try {
56
- oldDocumentPicker = require ( 'react-native-document-picker' ) as typeof OldDocumentPicker ;
57
- } catch { }
58
-
59
- try {
60
- newDocumentsPicker = require ( '@react-native-documents/picker' ) as typeof NewDocumentsPicker ;
61
- } catch { }
62
-
63
- if ( newDocumentsPicker && documentPickerModule === newDocumentsPicker ) {
64
- return await openDocumentByNewDocumentsPicker ( documentPickerModule , options ) ;
65
- } else if ( oldDocumentPicker && documentPickerModule === oldDocumentPicker ) {
55
+ if ( isOldModule ( documentPickerModule ) ) {
66
56
return await openDocumentByOldDocumentPicker ( documentPickerModule , options ) ;
67
- } else {
68
- const errorMessage =
69
- 'Document picker module not found. Please install either react-native-document-picker or @react-native-documents/picker.' ;
70
- Logger . error ( errorMessage ) ;
71
- throw new Error ( errorMessage ) ;
72
57
}
58
+ return await openDocumentByNewDocumentsPicker ( documentPickerModule , options ) ;
73
59
}
0 commit comments