UNPKG

react-native-scanbot-sdk

Version:

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

72 lines (64 loc) 2.37 kB
import { ColorValue, ViewStyle } from 'react-native'; import { StyleProp } from 'react-native/Libraries/StyleSheet/StyleSheet'; import { ImageRef, ImageRotation } from '../../imageRef'; import { DeepPartial, Point } from '../../utils'; export type FileSrc = { imageFileUri: string }; export type ImageSrc = FileSrc | { imageRefUUID: string }; export type CroppingViewRotation = 'CLOCKWISE' | 'COUNTERCLOCKWISE'; export interface ScanbotCroppingViewProperties { style?: StyleProp<ViewStyle>; /** A result callback that is triggered with `extractCroppedArea`. */ onCroppedAreaResult: (result: CroppingViewResult) => void; /** An error callback that is triggered when an error occurs. */ onError?: (errorMessage: string) => void; /** * The source of the image, specified either by a local file URI * or an ImageRef UUID. */ src: ImageSrc; /** The color of the non-snapped edges. */ edgeColor?: ColorValue; /** The width of the edges. */ edgeLineWidth?: number; /** The color of the edges when positioned on the magnetic line. */ edgeColorOnLine?: ColorValue; /** The color of the anchor points. */ anchorPointsColor?: ColorValue; } export interface ScanbotCroppingViewHandle { /** Reset the drawn polygons */ resetPolygon: () => void; /** Detect a document on the source image and draw the polygons. */ detectPolygon: () => void; /** Rotates the source image. */ rotate: (rotation: CroppingViewRotation) => void; /** Extracts cropped area from the currently drawn polygon area on the image */ extractCroppedArea: () => void; } export class CroppingViewResult { /** * The polygon of the cropped area. */ public readonly polygon: Point[] = []; /** * The rotation of the resulting cropped area */ public readonly rotation: ImageRotation = 'NONE'; /** A crop from the input image. */ public readonly sourceImage: ImageRef | null = null; constructor(source: DeepPartial<CroppingViewResult>) { if (source.polygon !== undefined) { this.polygon = source.polygon.map((it: any) => { return { x: it.x, y: it.y }; }); } if (source.sourceImage !== undefined) { this.sourceImage = source.sourceImage != null ? ImageRef.From(source.sourceImage) : null; } if (source.rotation !== undefined) { this.rotation = source.rotation; } } }