UNPKG

react-native-scanbot-barcode-scanner-sdk

Version:

Scanbot Barcode Scanner SDK React Native Plugin for Android and iOS

144 lines (143 loc) 7.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ScanbotBarcodeCameraView = void 0; var _react = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _types = require("../../types"); var _ScanbotBarcodeScannerViewNativeComponent = _interopRequireWildcard(require("../spec/ScanbotBarcodeScannerViewNativeComponent")); function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } const ScanbotBarcodeCameraView = exports.ScanbotBarcodeCameraView = /*#__PURE__*/(0, _react.forwardRef)(({ onBarcodeScannerResult, onBarcodeTap, onError, ...props }, forwardedRef) => { const viewRef = (0, _react.useRef)(null); const boundBarcodeItemOverlayViews = (0, _react.useRef)(new Map()); (0, _react.useImperativeHandle)(forwardedRef, () => { return { freezeCamera() { if (viewRef.current) { _ScanbotBarcodeScannerViewNativeComponent.Commands.freezeCamera(viewRef.current); } }, unfreezeCamera() { if (viewRef.current) { _ScanbotBarcodeScannerViewNativeComponent.Commands.unfreezeCamera(viewRef.current); } } }; }, []); const _onBarcodeScannerResult = (0, _react.useCallback)(async event => { const result = event.nativeEvent.result; if (result) { const barcodeItems = _reactNative.Platform.OS === 'ios' ? JSON.parse(result) : result; (0, _types.autorelease)(() => { onBarcodeScannerResult(barcodeItems.map(item => new _types.BarcodeItem(item))); }); if (props.selectionOverlayConfig?.barcodeItemOverlayViewBinder) { for (let barcode of barcodeItems) { const barcodeItemUuid = barcode.text + barcode.upcEanExtension + '_' + barcode.format; const barcodeItemNextBind = boundBarcodeItemOverlayViews.current.get(barcodeItemUuid); if (barcodeItemNextBind === undefined || barcodeItemNextBind !== -1 && Date.now() >= barcodeItemNextBind) { boundBarcodeItemOverlayViews.current.set(barcodeItemUuid, -1); const bindingConfig = await props.selectionOverlayConfig.barcodeItemOverlayViewBinder(barcode); if (bindingConfig.refreshRate !== undefined && bindingConfig.refreshRate > 0) { boundBarcodeItemOverlayViews.current.set(barcodeItemUuid, Date.now() + bindingConfig.refreshRate); } if (viewRef.current != null) { _ScanbotBarcodeScannerViewNativeComponent.Commands.bindBarcodeItemOverlayView(viewRef.current, barcodeItemUuid, JSON.stringify(bindingConfig)); } } } } else { boundBarcodeItemOverlayViews.current.clear(); } } }, [props.selectionOverlayConfig, boundBarcodeItemOverlayViews, onBarcodeScannerResult]); const _onBarcodeSelectionResult = (0, _react.useCallback)(event => { const result = event.nativeEvent.result; if (result && onBarcodeTap) { (0, _types.autorelease)(() => { onBarcodeTap(new _types.BarcodeItem(_reactNative.Platform.OS === 'ios' ? JSON.parse(result)[0] : result)); }); } }, [onBarcodeTap]); const _onError = (0, _react.useCallback)(event => { if (onError) { onError((0, _types.createSBError)(event.nativeEvent)); } }, [onError]); return /*#__PURE__*/_react.default.createElement(_reactNative.View, { style: [styles.container, props.style] }, /*#__PURE__*/_react.default.createElement(_reactNative.View, { pointerEvents: 'box-none', style: [styles.contentContainerStyle, props.contentContainerStyle] }, props.children), /*#__PURE__*/_react.default.createElement(_ScanbotBarcodeScannerViewNativeComponent.default //FinderConfigs , { finderEnabled: props.finderConfig?.viewFinderEnabled, finderStrokeWidth: props.finderConfig?.finderLineWidth, finderMinPadding: props.finderConfig?.minPadding, finderStrokeColor: props.finderConfig?.finderLineColor, finderOverlayColor: props.finderConfig?.overlayColor, finderInset: props.finderConfig?.finderInset, finderRequiredAspectRatios: props.finderConfig?.requiredAspectRatio //CameraConfigs , cameraZoomFactor: _reactNative.Platform.select({ ios: props.cameraConfig?.cameraZoomFactor ? parseFloat(props.cameraConfig?.cameraZoomFactor.toFixed(2)) : undefined, android: props.cameraConfig?.cameraZoomFactor !== undefined ? (props.cameraConfig?.cameraZoomRange?.minZoom || 1) + ((props.cameraConfig?.cameraZoomRange?.maxZoom || 12) - (props.cameraConfig?.cameraZoomRange?.minZoom || 1)) * props.cameraConfig?.cameraZoomFactor : undefined }), cameraZoomRange: props.cameraConfig?.cameraZoomRange, minFocusDistanceLock: props.cameraConfig?.minFocusDistanceLock, cameraModule: props.cameraConfig?.cameraModule //SelectionOverlayConfig , overlayEnabled: props.selectionOverlayConfig?.overlayEnabled, overlayPolygonColor: props.selectionOverlayConfig?.polygonColor, overlayStrokeColor: props.selectionOverlayConfig?.strokeColor, overlayTextFormat: props.selectionOverlayConfig?.textFormat, overlayTextColor: props.selectionOverlayConfig?.textColor, overlayTextContainerColor: props.selectionOverlayConfig?.textContainerColor, overlayLoadingTextValue: props.selectionOverlayConfig?.loadingTextValue, overlayBarcodeItemOverlayViewBinder: props.selectionOverlayConfig?.barcodeItemOverlayViewBinder !== undefined //Barcode Scanner Configuration , configFormatConfigurations: props.barcodeScannerConfiguration?.barcodeFormatConfigurations, configExtractedDocumentFormats: props.barcodeScannerConfiguration?.extractedDocumentFormats, configOnlyAcceptDocuments: props.barcodeScannerConfiguration?.onlyAcceptDocuments, configReturnBarcodeImage: props.barcodeScannerConfiguration?.returnBarcodeImage, configEngineMode: props.barcodeScannerConfiguration?.engineMode, configAccumulation: props.barcodeScannerConfiguration?.accumulationConfig, configOptimizedForOverlays: props.barcodeScannerConfiguration?.optimizedForOverlays //Other , flashEnabled: props.flashEnabled, scanningEnabled: props.scanningEnabled, hardwareButtonsEnabled: props.hardwareButtonsEnabled //View , style: styles.container, ref: viewRef //Result , onBarcodeScannerResult: _onBarcodeScannerResult, onSelectBarcodeResult: _onBarcodeSelectionResult, onError: _onError })); }); const styles = _reactNative.StyleSheet.create({ container: { flex: 1 }, contentContainerStyle: { position: 'absolute', width: '100%', height: '100%', zIndex: 2 } }); //# sourceMappingURL=ScanbotBarcodeCameraView.js.map