UNPKG

react-native-scanbot-sdk

Version:

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

131 lines (130 loc) 6.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ScanbotBarcodeCameraView = void 0; var _react = _interopRequireWildcard(require("react")); var _ScanbotBarcodeScannerViewNativeComponent = _interopRequireWildcard(require("../spec/ScanbotBarcodeScannerViewNativeComponent")); var _reactNative = require("react-native"); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } const ScanbotBarcodeCameraView = exports.ScanbotBarcodeCameraView = /*#__PURE__*/(0, _react.forwardRef)(({ onBarcodeScannerResult, ...props }, forwardedRef) => { const viewRef = (0, _react.useRef)(null); const boundBarcodeItemOverlayViews = (0, _react.useRef)(new Set()); (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; const selectionOverlayAutoSelectDisabled = props.selectionOverlayConfig?.overlayEnabled && !props.selectionOverlayConfig?.automaticSelectionEnabled; if (result) { const barcodeScannerResult = _reactNative.Platform.OS === 'ios' ? JSON.parse(result) : result; if (!selectionOverlayAutoSelectDisabled) { onBarcodeScannerResult(barcodeScannerResult); } if (props.selectionOverlayConfig?.barcodeItemOverlayViewBinder) { for (let barcode of barcodeScannerResult.barcodes) { const barcodeItemUuid = barcode.textWithExtension + '_' + barcode.type; if (!boundBarcodeItemOverlayViews.current.has(barcodeItemUuid)) { boundBarcodeItemOverlayViews.current.add(barcodeItemUuid); const bindingConfig = await props.selectionOverlayConfig.barcodeItemOverlayViewBinder(barcode); if (viewRef.current != null) { _ScanbotBarcodeScannerViewNativeComponent.Commands.bindBarcodeItemOverlayView( //@ts-ignore viewRef.current, barcodeItemUuid, JSON.stringify(bindingConfig)); } } } } } }, [props.selectionOverlayConfig, boundBarcodeItemOverlayViews, onBarcodeScannerResult]); const _onBarcodeSelectionResult = (0, _react.useCallback)(event => { const result = event.nativeEvent.result; const selectionOverlayAutoSelectDisabled = props.selectionOverlayConfig?.overlayEnabled && !props.selectionOverlayConfig?.automaticSelectionEnabled; if (selectionOverlayAutoSelectDisabled && result && _reactNative.Platform.OS === 'android') { const barcodeItemResult = result; onBarcodeScannerResult({ barcodes: [barcodeItemResult] }); } else if (selectionOverlayAutoSelectDisabled && result && _reactNative.Platform.OS === 'ios') { const barcodeResult = JSON.parse(result); onBarcodeScannerResult(barcodeResult); } }, [onBarcodeScannerResult, props.selectionOverlayConfig?.automaticSelectionEnabled, props.selectionOverlayConfig?.overlayEnabled]); 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 //DetectorConfigs , detectorConfig: props.detectorConfig //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 //Other , flashEnabled: props.flashEnabled, scanningEnabled: props.scanningEnabled //View , style: styles.container, ref: viewRef //Result , onBarcodeScannerResult: _onBarcodeScannerResult, onSelectBarcodeResult: _onBarcodeSelectionResult })); }); const styles = _reactNative.StyleSheet.create({ container: { flex: 1 }, contentContainerStyle: { position: 'absolute', width: '100%', height: '100%', zIndex: 2 } }); //# sourceMappingURL=ScanbotBarcodeCameraView.js.map