@sendbird/uikit-react-native
Version:
Sendbird UIKit for React Native: A feature-rich and customizable chat UI kit with messaging, channel management, and user authentication.
59 lines • 2.08 kB
JavaScript
import { Logger } from '@sendbird/uikit-utils';
import SBUError from '../libs/SBUError';
import normalizeFile from '../utils/normalizeFile';
async function openDocumentByOldDocumentPicker(documentPickerModule, options) {
Logger.warn('please update to @react-native-documents/picker');
try {
const {
uri,
size,
name,
type
} = await documentPickerModule.pickSingle();
return normalizeFile({
uri,
size,
name,
type
});
} catch (e) {
if (!documentPickerModule.isCancel(e) && documentPickerModule.isInProgress(e)) {
var _options$onOpenFailur;
options === null || options === void 0 || (_options$onOpenFailur = options.onOpenFailure) === null || _options$onOpenFailur === void 0 || _options$onOpenFailur.call(options, SBUError.UNKNOWN, e);
}
return null;
}
}
async function openDocumentByNewDocumentsPicker(documentPickerModule, options) {
try {
const results = await documentPickerModule.pick();
const {
uri,
size,
name,
type
} = results[0];
return normalizeFile({
uri,
size,
name,
type
});
} catch (e) {
if (!documentPickerModule.isErrorWithCode(documentPickerModule.errorCodes.OPERATION_CANCELED) && documentPickerModule.isErrorWithCode(documentPickerModule.errorCodes.IN_PROGRESS)) {
var _options$onOpenFailur2;
options === null || options === void 0 || (_options$onOpenFailur2 = options.onOpenFailure) === null || _options$onOpenFailur2 === void 0 || _options$onOpenFailur2.call(options, SBUError.UNKNOWN, e);
}
return null;
}
}
function isOldModule(documentPicker) {
return 'pickSingle' in documentPicker && typeof documentPicker.pickSingle === 'function';
}
export async function openDocument(documentPickerModule, options) {
if (isOldModule(documentPickerModule)) {
return await openDocumentByOldDocumentPicker(documentPickerModule, options);
}
return await openDocumentByNewDocumentsPicker(documentPickerModule, options);
}
//# sourceMappingURL=openDocument.native.js.map