@@ -13,7 +13,7 @@ async function openDocumentByOldDocumentPicker(
1313 documentPickerModule : typeof OldDocumentPicker ,
1414 options ?: OpenDocumentOptions ,
1515) : Promise < FilePickerResponse > {
16- Logger . log ( 'called openDocumentByOldDocumentPicker ') ;
16+ Logger . warn ( 'please update to @react-native-documents/picker ') ;
1717 try {
1818 const { uri, size, name, type } = await documentPickerModule . pickSingle ( ) ;
1919 return normalizeFile ( { uri, size, name, type } ) ;
@@ -29,7 +29,6 @@ async function openDocumentByNewDocumentsPicker(
2929 documentPickerModule : typeof NewDocumentsPicker ,
3030 options ?: OpenDocumentOptions ,
3131) : Promise < FilePickerResponse > {
32- Logger . log ( 'called openDocumentByNewDocumentsPicker' ) ;
3332 try {
3433 const results = await documentPickerModule . pick ( ) ;
3534 const { uri, size, name, type } = results [ 0 ] ;
@@ -45,29 +44,16 @@ async function openDocumentByNewDocumentsPicker(
4544 }
4645}
4746
47+ function isOldModule ( documentPicker : DocumentPicker ) : documentPicker is typeof OldDocumentPicker {
48+ return typeof ( documentPicker as typeof OldDocumentPicker ) . pickSingle === 'function' ;
49+ }
50+
4851export async function openDocument (
4952 documentPickerModule : DocumentPicker ,
5053 options ?: OpenDocumentOptions ,
5154) : 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 ) ) {
6656 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 ) ;
7257 }
58+ return await openDocumentByNewDocumentsPicker ( documentPickerModule , options ) ;
7359}
0 commit comments