UNPKG

react-native-scanbot-sdk

Version:

Scanbot Document and Barcode Scanner SDK React Native Plugin for Android and iOS

100 lines (96 loc) 5.13 kB
import { NativeEventEmitter, NativeModules, Platform } from 'react-native'; import { SingleScanningMode } from './barcode/SingleScanningModeUseCase'; import { MultipleScanningMode } from './barcode/MultipleScanningModeUseCase'; const LINKING_ERROR = `The package 'react-native-scanbot-sdk' doesn't seem to be linked. Make sure: \n\n` + Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n'; const ScanbotSDKUIImpl = NativeModules.RNScanbotRTUUI ? NativeModules.RNScanbotRTUUI : new Proxy({}, { get() { throw new Error(LINKING_ERROR); } }); const isIOS = Platform.OS === 'ios'; /** * Opens the Ready-To-Use UI screen for scanning Barcodes and QR-Codes with the desired configuration. */ export function startBarcodeScanner(config) { const barcodeItemMapperEventName = 'barcodeItemMapperEvent'; let barcodeItemMapperCallback = null; let barcodeItemMapperEventEmitter = null; if (config.useCase instanceof SingleScanningMode || config.useCase instanceof MultipleScanningMode) { barcodeItemMapperCallback = config.useCase.barcodeInfoMapping.barcodeItemMapper; if (barcodeItemMapperCallback) { barcodeItemMapperEventEmitter = new NativeEventEmitter(ScanbotSDKUIImpl); barcodeItemMapperEventEmitter.removeAllListeners(barcodeItemMapperEventName); barcodeItemMapperEventEmitter.addListener(barcodeItemMapperEventName, barcodeItem => { const barcodeItemUuid = `${barcodeItem.textWithExtension}_${barcodeItem.type ?? ''}`; barcodeItemMapperCallback(barcodeItem, barcodeMappedData => ScanbotSDKUIImpl.onBarcodeItemMapper(barcodeItemUuid, barcodeMappedData), () => ScanbotSDKUIImpl.onBarcodeItemMapper(barcodeItemUuid, null)); }); // On iOS, the communication with the native part is throwing an error (startBarcodeScannerV2) because of the barcodeItemMapper // callback in the configuration class (not parsable), that's why we need to remove it before executing startBarcodeScannerV2 method config.useCase.barcodeInfoMapping.barcodeItemMapper = null; return new Promise((resolve, reject) => { ScanbotSDKUIImpl.startBarcodeScannerV2(isIOS ? JSON.stringify(config) : config, true).then(result => { barcodeItemMapperEventEmitter?.removeAllListeners(barcodeItemMapperEventName); barcodeItemMapperEventEmitter = null; resolve(result); }).catch(error => { barcodeItemMapperEventEmitter?.removeAllListeners(barcodeItemMapperEventName); barcodeItemMapperEventEmitter = null; reject(error); }); }); } } return ScanbotSDKUIImpl.startBarcodeScannerV2(isIOS ? JSON.stringify(config) : config, false); } /** * Opens the Ready-To-Use UI Document Scanner screen with the desired configuration. */ export function startDocumentScanner(config) { return ScanbotSDKUIImpl.startDocumentScannerV2(isIOS ? JSON.stringify(config) : config); } /** * Opens the Ready-To-Use UI Cropping screen with the desired configuration. */ export function startCroppingScreen(config) { return ScanbotSDKUIImpl.startCroppingScreenV2(isIOS ? JSON.stringify(config) : config); } export * from './barcode/ArTrackingOverlayConfiguration'; export * from './barcode/BarcodeInfoMapping'; export * from './barcode/BarcodeItem'; export * from './barcode/BarcodeRecognizerConfiguration'; export * from './barcode/BarcodeResult'; export * from './barcode/BarcodeScannerConfiguration'; export * from './barcode/BarcodeTextLocalization'; export * from './barcode/BarcodeUseCase'; export * from './barcode/FindAndPickScanningModeUseCase'; export * from './barcode/MultipleScanningModeUseCase'; export * from './barcode/SingleScanningModeUseCase'; export * from './common/ActionBarConfiguration'; export * from './common/CameraConfiguration'; export * from './common/CameraPermission'; export * from './common/Common'; export * from './common/NavigationBarConfiguration'; export * from './common/ScanbotAlertDialog'; export * from './common/TopBarConfiguration'; export * from './common/UserGuidanceConfiguration'; export * from './common/ViewFinderConfiguration'; export * from './document/AcknowledgementScreenConfiguration'; export * from './document/CameraScreenConfiguration'; export * from './document/CroppingConfiguration'; export * from './document/CroppingScreenConfiguration'; export * from './document/CroppingTextLocalization'; export * from './document/DocumentScannerCameraConfiguration'; export * from './document/DocumentScannerGuidanceVisibility'; export * from './document/DocumentScannerOutputSettings'; export * from './document/DocumentScannerScreens'; export * from './document/DocumentScannerTextLocalization'; export * from './document/DocumentScannerUserGuidance'; export * from './document/DocumentScanningFlow'; export * from './document/IntroductionScreenConfiguration'; export * from './document/ReorderPagesScreenConfiguration'; export * from './document/ReviewScreenConfiguration'; export * from './BarcodeItemMapper'; //# sourceMappingURL=index.js.map