UNPKG

react-native-scanbot-sdk

Version:

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

84 lines 2.52 kB
import React, { forwardRef, useCallback, useImperativeHandle, useMemo, useRef } from 'react'; import { StyleSheet, View } from 'react-native'; import { autorelease } from '../../imageRef'; import NativeCroppingView, { Commands } from '../spec/ScanbotCroppingViewNativeComponent'; import { CroppingViewResult } from './ScanbotCroppingViewProperties'; function isFileSrc(src) { return src.imageFileUri !== undefined; } export const ScanbotCroppingView = /*#__PURE__*/forwardRef(({ onCroppedAreaResult, onError, ...props }, forwardedRef) => { const viewRef = useRef(null); useImperativeHandle(forwardedRef, () => { return { detectPolygon() { if (viewRef.current) { Commands.detectPolygon(viewRef.current); } }, resetPolygon() { if (viewRef.current) { Commands.resetPolygon(viewRef.current); } }, rotate(rotation) { if (viewRef.current) { Commands.rotate(viewRef.current, rotation === 'CLOCKWISE'); } }, extractCroppedArea() { if (viewRef.current) { Commands.extractCroppedArea(viewRef.current); } } }; }); const _nativeViewSrc = useMemo(() => { if (isFileSrc(props.src)) { return { imageFileUri: props.src.imageFileUri, imageRef: undefined }; } else { return { imageFileUri: undefined, imageRef: props.src.imageRefUUID }; } }, [props.src]); const _onCroppedAreaResult = useCallback(event => { if (event.nativeEvent.result !== null) { autorelease(() => { onCroppedAreaResult(new CroppingViewResult(JSON.parse(event.nativeEvent.result))); }); } }, [onCroppedAreaResult]); const _onError = useCallback(event => { if (onError) { onError(event.nativeEvent.result); } }, [onError]); return /*#__PURE__*/React.createElement(View, { style: [styles.container, props.style] }, /*#__PURE__*/React.createElement(NativeCroppingView, { ref: viewRef, imageFileSrc: _nativeViewSrc.imageFileUri, imageRefSrc: _nativeViewSrc.imageRef, onCroppedAreaResult: _onCroppedAreaResult, onError: _onError, edgeColor: props.edgeColor, edgeLineWidth: props.edgeLineWidth, edgeColorOnLine: props.edgeColorOnLine, anchorPointsColor: props.anchorPointsColor, style: styles.container })); }); const styles = StyleSheet.create({ container: { flex: 1 } }); //# sourceMappingURL=ScanbotCroppingView.js.map