react-native-scanbot-sdk
Version:
Scanbot Document and Barcode Scanner SDK React Native Plugin for Android and iOS
92 lines (91 loc) • 3.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ScanbotCroppingView = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _imageRef = require("../../imageRef");
var _ScanbotCroppingViewNativeComponent = _interopRequireWildcard(require("../spec/ScanbotCroppingViewNativeComponent"));
var _ScanbotCroppingViewProperties = require("./ScanbotCroppingViewProperties");
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; }
function isFileSrc(src) {
return src.imageFileUri !== undefined;
}
const ScanbotCroppingView = exports.ScanbotCroppingView = /*#__PURE__*/(0, _react.forwardRef)(({
onCroppedAreaResult,
onError,
...props
}, forwardedRef) => {
const viewRef = (0, _react.useRef)(null);
(0, _react.useImperativeHandle)(forwardedRef, () => {
return {
detectPolygon() {
if (viewRef.current) {
_ScanbotCroppingViewNativeComponent.Commands.detectPolygon(viewRef.current);
}
},
resetPolygon() {
if (viewRef.current) {
_ScanbotCroppingViewNativeComponent.Commands.resetPolygon(viewRef.current);
}
},
rotate(rotation) {
if (viewRef.current) {
_ScanbotCroppingViewNativeComponent.Commands.rotate(viewRef.current, rotation === 'CLOCKWISE');
}
},
extractCroppedArea() {
if (viewRef.current) {
_ScanbotCroppingViewNativeComponent.Commands.extractCroppedArea(viewRef.current);
}
}
};
});
const _nativeViewSrc = (0, _react.useMemo)(() => {
if (isFileSrc(props.src)) {
return {
imageFileUri: props.src.imageFileUri,
imageRef: undefined
};
} else {
return {
imageFileUri: undefined,
imageRef: props.src.imageRefUUID
};
}
}, [props.src]);
const _onCroppedAreaResult = (0, _react.useCallback)(event => {
if (event.nativeEvent.result !== null) {
(0, _imageRef.autorelease)(() => {
onCroppedAreaResult(new _ScanbotCroppingViewProperties.CroppingViewResult(JSON.parse(event.nativeEvent.result)));
});
}
}, [onCroppedAreaResult]);
const _onError = (0, _react.useCallback)(event => {
if (onError) {
onError(event.nativeEvent.result);
}
}, [onError]);
return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
style: [styles.container, props.style]
}, /*#__PURE__*/_react.default.createElement(_ScanbotCroppingViewNativeComponent.default, {
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 = _reactNative.StyleSheet.create({
container: {
flex: 1
}
});
//# sourceMappingURL=ScanbotCroppingView.js.map