react-native-scanbot-sdk
Version:
Scanbot Document and Barcode Scanner SDK React Native Plugin for Android and iOS
84 lines • 3.34 kB
JavaScript
import React, { forwardRef, useCallback, useImperativeHandle, useRef } from 'react';
import { StyleSheet, View, Platform } from 'react-native';
import NativeDocumentScannerView, { Commands } from '../spec/ScanbotDocumentScannerViewNativeComponent';
export const ScanbotDocumentScannerView = /*#__PURE__*/forwardRef(({
onDocumentScannerResult,
onDetectionResult,
...props
}, forwardedRef) => {
const viewRef = useRef(null);
useImperativeHandle(forwardedRef, () => {
return {
freezeCamera() {
if (viewRef.current) {
Commands.freezeCamera(viewRef.current);
}
},
unfreezeCamera() {
if (viewRef.current) {
Commands.unfreezeCamera(viewRef.current);
}
},
snapDocument() {
if (viewRef.current) {
Commands.snapDocument(viewRef.current);
}
}
};
}, []);
const _onDocumentScannerResult = useCallback(event => {
const result = event.nativeEvent.result;
if (result) {
onDocumentScannerResult(result);
}
}, [onDocumentScannerResult]);
const _onDetectionResult = useCallback(event => {
if (event.nativeEvent.result) {
onDetectionResult && onDetectionResult(Platform.OS === 'ios' ? JSON.parse(event.nativeEvent.result) : event.nativeEvent.result);
}
}, [onDetectionResult]);
return /*#__PURE__*/React.createElement(View, {
style: [styles.container, props.style]
}, /*#__PURE__*/React.createElement(NativeDocumentScannerView, {
ref: viewRef,
style: styles.container,
onDocumentScannerResult: _onDocumentScannerResult,
onDetectionResult: _onDetectionResult,
acceptedAngleScore: props.acceptedAngleScore,
acceptedBrightnessThreshold: props.acceptedBrightnessThreshold,
acceptedSizeScore: props.acceptedSizeScore,
autoSnappingEnabled: props.autoSnappingEnabled,
autoSnappingSensitivity: props.autoSnappingSensitivity,
autoSnappingDelay: props.autoSnappingDelay,
cameraModule: props.cameraModule,
cameraPreviewMode: props.cameraPreviewMode,
flashEnabled: props.flashEnabled,
ignoreBadAspectRatio: props.ignoreBadAspectRatio,
photoQualityPrioritization: props.photoQualityPrioritization,
touchToFocusEnabled: props.touchToFocusEnabled,
requiredAspectRatios: props.requiredAspectRatios,
finderEnabled: props.finderEnabled,
finderLineColor: props.finderLineColor,
finderLineWidth: props.finderLineWidth,
finderOverlayColor: props.finderOverlayColor,
finderCornerRadius: props.finderCornerRadius,
finderMinimumPadding: props.finderMinimumPadding,
finderAspectRatio: props.finderAspectRatio,
polygonEnabled: props.polygonEnabled,
polygonBackgroundColor: props.polygonBackgroundColor,
polygonBackgroundColorOK: props.polygonBackgroundColorOK,
polygonColor: props.polygonColor,
polygonColorOK: props.polygonColorOK,
polygonLineWidth: props.polygonLineWidth,
polygonCornerRadius: props.polygonCornerRadius,
polygonAutoSnapProgressColor: props.polygonAutoSnapProgressColor,
polygonAutoSnapProgressLineWidth: props.polygonAutoSnapProgressLineWidth,
polygonAutoSnapProgressEnabled: props.polygonAutoSnapProgressEnabled
}));
});
const styles = StyleSheet.create({
container: {
flex: 1
}
});
//# sourceMappingURL=ScanbotDocumentScannerView.js.map