react-native-scanbot-sdk
Version:
Scanbot Document and Barcode Scanner SDK React Native Plugin for Android and iOS
149 lines (140 loc) • 6.33 kB
text/typescript
import React from 'react';
import { ColorValue, ViewStyle } from 'react-native';
import { StyleProp } from 'react-native/Libraries/StyleSheet/StyleSheet';
import {
BarcodeDocumentFormat,
BarcodeFormatConfigurationBase,
BarcodeItem,
BarcodeScannerEngineMode,
} from '../../barcode';
import { BarcodeOverlayTextFormat, CameraModule, ZoomRange } from '../../base';
import { CameraViewAspectRatio, CameraViewFinderInset } from '../CameraViewTypes';
export interface ScanbotBarcodeCameraViewProperties {
/** Configuration properties of the finder overlay */
finderConfig?: FinderConfig;
/** Configuration properties of the camera device */
cameraConfig?: CameraConfig;
/** The selection overlay configuration. */
selectionOverlayConfig?: SelectionOverlayConfig;
/** Configuration for the barcode scanner **/
barcodeScannerConfiguration?: BarcodeCameraViewScannerConfiguration;
/** Whether flash is toggled on or off. */
flashEnabled?: boolean;
/**
* Enable or disable barcode detection.
* If disabled, the camera preview is active but no barcodes will be detected.
* Default is enabled.
*/
scanningEnabled?: boolean;
/**
* Controls whether the hardware volume buttons and the new hardware camera control
* button should snap or not. Available in iOS 17.2 and later.
*/
hardwareButtonsEnabled?: boolean;
/* The result of the barcode scanner */
onBarcodeScannerResult: (result: BarcodeItem[]) => void;
style?: StyleProp<ViewStyle>;
contentContainerStyle?: StyleProp<ViewStyle>;
children?: React.ReactNode;
}
/** Configuration properties of the finder overlay */
export interface FinderConfig {
/** Display the region of interest. The default value is TRUE. */
viewFinderEnabled?: boolean;
/** Width of finder frame border. */
finderLineWidth?: number;
/** Color of finder frame border. */
finderLineColor?: string;
/** Background color of the detection overlay. */
overlayColor?: string;
/** The minimum space from view finders outer edges to the view edges. */
finderInset?: CameraViewFinderInset;
/** Initial padding for insets. Android only. */
minPadding?: number;
/** Aspect ratio of finder frame (width \ height), which is used to build the actual finder frame. */
requiredAspectRatio?: CameraViewAspectRatio;
}
/** Configuration properties of the camera device */
export interface CameraConfig {
/** The relative initial zoom level of the camera in the range (0,1), where 0 is zoomed out and 1 is zoomed in. The default value is 0.0. */
cameraZoomFactor?: number;
/** The range of valid camera zoom factors. Default value is (1.0; 12.0). */
cameraZoomRange?: ZoomRange;
/** The camera module to be used for barcode scanning */
cameraModule?: CameraModule;
/** Lock focus distance withing the minimum possible range */
minFocusDistanceLock?: boolean;
}
/** The selection overlay configuration. */
export interface SelectionOverlayConfig {
/** Whether the barcode selection overlay is enabled or not. */
overlayEnabled?: boolean;
/** Define the way of how to show barcode data with selection overlay. */
textFormat?: BarcodeOverlayTextFormat;
/** The color of the polygon in the selection overlay. */
polygonColor?: ColorValue;
/** The color of the text in the selection overlay. */
textColor?: ColorValue;
/** The color of the texts background in the selection overlay. */
textContainerColor?: ColorValue;
/** The color of the polygon border. */
strokeColor?: ColorValue;
/** Whether the barcode is highlighted automatically when being detected or not. */
automaticSelectionEnabled?: boolean;
/** Only used if the barcodeItemOverlayViewBinder callback is set. */
loadingTextValue?: string;
/** Callback that configures the selection overlay for each barcode item individually. */
barcodeItemOverlayViewBinder?: (
barcodeItem: BarcodeItem
) => Promise<BarcodeItemOverlayViewConfig> | BarcodeItemOverlayViewConfig;
}
export interface BarcodeCameraViewScannerConfiguration {
/**
Options for barcode decoding.
*/
barcodeFormatConfigurations?: BarcodeFormatConfigurationBase[];
/**
List of document formats to be extracted.
Barcodes that decode to one of the extracted document formats will have the extractedDocument field in BarcodeItem populated with the parsed document.
By default, all supported barcode document formats are accepted.
If empty, no barcodes will be parsed into documents.
*/
extractedDocumentFormats?: BarcodeDocumentFormat[];
/**
If true and acceptedDocumentFormats is not empty, then barcodes that don't decode to one of the accepted document formats will be ignored.
Default is false
*/
onlyAcceptDocuments?: boolean;
/**
If true, the barcode image will be returned in the BarcodeItem.
Default is false
*/
returnBarcodeImage?: boolean;
/**
The engine mode for barcode scanning.
Default is NEXT_GEN
*/
engineMode?: BarcodeScannerEngineMode;
}
export interface ScanbotBarcodeCameraViewHandle {
/** Freezes the camera preview */
freezeCamera(): void;
/** Unfreezes the previously frozen camera preview */
unfreezeCamera(): void;
}
export interface BarcodeItemOverlayViewConfig {
/** Custom text in the selection overlay. If not set, the textFormat property from the SelectionOverlayConfig is taken into account. */
text?: string;
/** The color of the text in the selection overlay. If not set, the textColor from SelectionOverlayConfig is used. */
textColor?: string;
/** The color of the texts background in the selection overlay. If not set, the textContainerColor from SelectionOverlayConfig is used. */
textContainerColor?: string;
/** The color of the polygon in the selection overlay. If not set, the polygonColor from SelectionOverlayConfig is used. */
polygonColor?: string;
/** The color of the polygon border. If not set, the strokeColor from SelectionOverlayConfig is used. */
strokeColor?: string;
/** If undefined or set to 0, the barcodeItemOverlayViewBinder callback is executed only once per scanning session for each barcode item.
* If set to a value greater than 0, the barcodeItemOverlayViewBinder will be executed after at least ***N milliseconds*** for every visible barcode item on the screen.
*/
refreshRate?: number;
}