react-native-scanbot-sdk
Version:
Scanbot Document and Barcode Scanner SDK React Native Plugin for Android and iOS
725 lines (708 loc) • 24.4 kB
text/typescript
import { ArOverlayFindAndPickConfiguration } from '../barcode/ArTrackingOverlayConfiguration';
import { ArOverlayGeneralConfiguration } from '../barcode/ArTrackingOverlayConfiguration';
import { ArOverlayPolygonConfiguration } from '../barcode/ArTrackingOverlayConfiguration';
import { BackgroundStyle } from '../common/Common';
import { BadgeStyle } from '../common/Common';
import { BadgedButton } from '../common/Common';
import { BarcodeInfoMapping } from '../barcode/BarcodeInfoMapping';
import { BarcodeItemConfiguration } from '../barcode/ArTrackingOverlayConfiguration';
import { BarcodeItemErrorState } from '../barcode/BarcodeInfoMapping';
import { BarcodeItemInfoPosition } from '../barcode/ArTrackingOverlayConfiguration';
import { BarcodeItemMapper } from '../BarcodeItemMapper';
import { BarcodeUseCase } from '../barcode/BarcodeUseCase';
import { ButtonConfiguration } from '../common/Common';
import { DeepPartial, PartiallyConstructible } from '../../utils';
import { ExpectedBarcode } from '../barcode/FindAndPickScanningModeUseCase';
import { FindAndPickArOverlayPolygonConfiguration } from '../barcode/ArTrackingOverlayConfiguration';
import { FindAndPickBadgeConfiguration } from '../barcode/ArTrackingOverlayConfiguration';
import { FindAndPickScanningMode } from '../barcode/FindAndPickScanningModeUseCase';
import { ForegroundStyle } from '../common/Common';
import { IconStyle } from '../common/Common';
import { PolygonStyle } from '../common/Common';
import { ScanbotAlertDialog } from '../common/ScanbotAlertDialog';
import { SingleScanningMode } from '../barcode/SingleScanningModeUseCase';
import { StyledText } from '../common/Common';
/**
Configuration of the mode used for scanning multiple barcodes.
- `COUNTING`:
Scan barcodes even if they have the same value and count the number of repeated barcodes.
- `UNIQUE`:
Only scan barcodes with unique values. Subsequent barcodes with the same values will be ignored.
*/
export type MultipleBarcodesScanningMode = 'COUNTING' | 'UNIQUE';
/**
Configuration of the barcode result sheet's default visibility state.
- `BUTTON`:
Result sheet is hidden and can be opened by pressing the button. The button can show the total barcode count.
- `COLLAPSED_SHEET`:
Result sheet is visible and collapsed and can be expanded by dragging it up.
*/
export type SheetMode = 'BUTTON' | 'COLLAPSED_SHEET';
/**
Configuration of the barcodes result sheet's height while collapsed.
- `SMALL`:
Result sheet is collapsed as much as possible, showing only the top part.
- `LARGE`:
Result sheet is not completely collapsed, revealing more information.
*/
export type CollapsedVisibleHeight = 'SMALL' | 'LARGE';
/**
Configuration of the preview mode for scanning multiple barcodes.
*/
export class Sheet extends PartiallyConstructible {
/**
Mode used for the preview for scanning multiple barcodes.
Default is COLLAPSED_SHEET
*/
public mode: SheetMode = 'COLLAPSED_SHEET';
/**
Height of the collapsed result sheet.
Default is SMALL
*/
public collapsedVisibleHeight: CollapsedVisibleHeight = 'SMALL';
/**
Configuration of the list button.
*/
public listButton: BadgedButton = new BadgedButton({});
/** @param source {@displayType `DeepPartial<Sheet>`} */
public constructor(source: DeepPartial<Sheet> = {}) {
super();
if (source.mode !== undefined) {
this.mode = source.mode;
}
if (source.collapsedVisibleHeight !== undefined) {
this.collapsedVisibleHeight = source.collapsedVisibleHeight;
}
if (source.listButton !== undefined) {
this.listButton = new BadgedButton(source.listButton);
}
}
}
/**
Configuration of the swipe-to-delete button.
*/
export class SwipeToDelete extends PartiallyConstructible {
/**
Whether swipe to delete is enabled or not.
Default is true
*/
public enabled: boolean = true;
/**
Color of the swipe-to-delete button.
Default is "?sbColorNegative"
*/
public backgroundColor: string = '?sbColorNegative';
/**
Color of the icon on the swipe-to-delete button.
Default is "?sbColorOnPrimary"
*/
public iconColor: string = '?sbColorOnPrimary';
/** @param source {@displayType `DeepPartial<SwipeToDelete>`} */
public constructor(source: DeepPartial<SwipeToDelete> = {}) {
super();
if (source.enabled !== undefined) {
this.enabled = source.enabled;
}
if (source.backgroundColor !== undefined) {
this.backgroundColor = source.backgroundColor;
}
if (source.iconColor !== undefined) {
this.iconColor = source.iconColor;
}
}
}
/**
Configuration of the dialog to manually edit the barcode count.
*/
export class ManualCountEditDialog extends PartiallyConstructible {
/**
Color of the edit dialog's background.
Default is "?sbColorSurface"
*/
public sheetColor: string = '?sbColorSurface';
/**
Color of the divider and separator lines in the edit dialog.
Default is "?sbColorOutline"
*/
public dividerColor: string = '?sbColorOutline';
/**
Background color of the overlay surrounding the edit dialog.
Default is "?sbColorModalOverlay"
*/
public modalOverlayColor: string = '?sbColorModalOverlay';
/**
Configuration of the edit dialog's title.
*/
public title: StyledText = new StyledText({ text: 'Update count', color: '?sbColorOnSurface' });
/**
Configuration of the edit dialog's info text.
*/
public info: StyledText = new StyledText({
text: 'Adjust the number of items you scanned.',
color: '?sbColorOnSurfaceVariant',
});
/**
Configuration of the edit dialog's confirm button. Hiding both the update and cancel buttons simultaneously is an undefined behavior.
*/
public updateButton: ButtonConfiguration = new ButtonConfiguration({
visible: true,
text: 'Update',
background: new BackgroundStyle({
strokeColor: '?sbColorPrimary',
fillColor: '?sbColorPrimary',
strokeWidth: 1.0,
}),
foreground: new ForegroundStyle({
iconVisible: false,
color: '?sbColorOnPrimary',
useShadow: false,
}),
});
/**
Configuration of the edit dialog's cancel button. Hiding both the update and cancel buttons simultaneously is an undefined behavior.
*/
public cancelButton: ButtonConfiguration = new ButtonConfiguration({
visible: true,
text: 'Cancel',
background: new BackgroundStyle({
strokeColor: '#00000000',
fillColor: '#00000000',
strokeWidth: 1.0,
}),
foreground: new ForegroundStyle({
iconVisible: false,
color: '?sbColorPrimary',
useShadow: false,
}),
});
/**
Configuration of the edit dialog's button to clear the entered count number.
*/
public clearTextButton: IconStyle = new IconStyle({
visible: true,
color: '?sbColorOnSurfaceVariant',
});
/** @param source {@displayType `DeepPartial<ManualCountEditDialog>`} */
public constructor(source: DeepPartial<ManualCountEditDialog> = {}) {
super();
if (source.sheetColor !== undefined) {
this.sheetColor = source.sheetColor;
}
if (source.dividerColor !== undefined) {
this.dividerColor = source.dividerColor;
}
if (source.modalOverlayColor !== undefined) {
this.modalOverlayColor = source.modalOverlayColor;
}
if (source.title !== undefined) {
this.title = new StyledText(source.title);
}
if (source.info !== undefined) {
this.info = new StyledText(source.info);
}
if (source.updateButton !== undefined) {
this.updateButton = new ButtonConfiguration(source.updateButton);
}
if (source.cancelButton !== undefined) {
this.cancelButton = new ButtonConfiguration(source.cancelButton);
}
if (source.clearTextButton !== undefined) {
this.clearTextButton = new IconStyle(source.clearTextButton);
}
}
}
/**
Configuration of the list containing the barcodes that have already been scanned.
*/
export class SheetContent extends PartiallyConstructible {
/**
Color of the list's background.
Default is "?sbColorSurface"
*/
public sheetColor: string = '?sbColorSurface';
/**
The color of the dividers in the list sheet.
Default is "?sbColorOutline"
*/
public dividerColor: string = '?sbColorOutline';
/**
Enables the user to change the number of scanned items by pressing +,-, or changing the number using a keyboard.
Default is true
*/
public manualCountChangeEnabled: boolean = true;
/**
The color of the outline of the manual counting buttons in the list sheet.
Default is "?sbColorOutline"
*/
public manualCountOutlineColor: string = '?sbColorOutline';
/**
Color of the buttons for manually changing the barcode count.
Default is "?sbColorPrimary"
*/
public manualCountChangeColor: string = '?sbColorPrimary';
/**
Configuration of the barcode list's title. By default displays the total number of scanned barcodes.
*/
public title: StyledText = new StyledText({ text: '%d items', color: '?sbColorOnSurface' });
/**
Configuration of the button for clearing the barcode list.
*/
public clearAllButton: ButtonConfiguration = new ButtonConfiguration({
visible: true,
text: 'Clear all',
background: new BackgroundStyle({
strokeColor: '#00000000',
fillColor: '#00000000',
strokeWidth: 1.0,
}),
foreground: new ForegroundStyle({
iconVisible: false,
color: '?sbColorOnSurface',
useShadow: false,
}),
});
/**
Configuration of the title of a barcode list entry (displaying the barcode's value).
*/
public barcodeItemTitle: StyledText = new StyledText({
visible: true,
text: 'BARCODE_TITLE',
color: '?sbColorOnSurface',
useShadow: false,
});
/**
Configuration of the subtitle of a barcode list entry (displaying the barcode's symbology).
*/
public barcodeItemSubtitle: StyledText = new StyledText({
text: 'BARCODE_SUBTITLE',
color: '?sbColorOnSurfaceVariant',
});
/**
Visibility of the barcode image in a barcode list entry.
Default is true
*/
public barcodeItemImageVisible: boolean = true;
/**
Configuration of the barcode list's submit button.
*/
public submitButton: ButtonConfiguration = new ButtonConfiguration({
visible: true,
text: 'Submit',
background: new BackgroundStyle({
strokeColor: '#00000000',
fillColor: '#00000000',
strokeWidth: 1.0,
}),
foreground: new ForegroundStyle({
iconVisible: false,
color: '?sbColorOnSurface',
useShadow: false,
}),
});
/**
Configuration of the button to start scanning displayed in an empty barcode list.
*/
public startScanningButton: ButtonConfiguration = new ButtonConfiguration({
visible: true,
text: 'Start scanning',
background: new BackgroundStyle({
strokeColor: '?sbColorPrimary',
fillColor: '?sbColorPrimary',
strokeWidth: 1.0,
}),
foreground: new ForegroundStyle({
iconVisible: true,
color: '?sbColorOnPrimary',
useShadow: false,
}),
});
/**
Configuration of the title displayed in an empty barcode list.
*/
public placeholderTitle: StyledText = new StyledText({
text: 'No barcodes here!',
color: '?sbColorOnSurface',
});
/**
Configuration of the subtitle displayed in an empty barcode list.
*/
public placeholderSubtitle: StyledText = new StyledText({
text: 'The barcode list is currently empty. Close this sheet and scan your items to add them.',
color: '?sbColorOnSurfaceVariant',
});
/**
Background color of the icon displayed in an empty barcode list.
Default is "?sbColorOutline"
*/
public placeholderIconBackground: string = '?sbColorOutline';
/**
Configuration of the icon displayed in an empty barcode list.
*/
public placeholderIcon: IconStyle = new IconStyle({ visible: true, color: '?sbColorOnSurface' });
/**
The style of the swipe-to-delete button.
*/
public swipeToDelete: SwipeToDelete = new SwipeToDelete({
enabled: true,
backgroundColor: '?sbColorNegative',
iconColor: '?sbColorOnPrimary',
});
/** @param source {@displayType `DeepPartial<SheetContent>`} */
public constructor(source: DeepPartial<SheetContent> = {}) {
super();
if (source.sheetColor !== undefined) {
this.sheetColor = source.sheetColor;
}
if (source.dividerColor !== undefined) {
this.dividerColor = source.dividerColor;
}
if (source.manualCountChangeEnabled !== undefined) {
this.manualCountChangeEnabled = source.manualCountChangeEnabled;
}
if (source.manualCountOutlineColor !== undefined) {
this.manualCountOutlineColor = source.manualCountOutlineColor;
}
if (source.manualCountChangeColor !== undefined) {
this.manualCountChangeColor = source.manualCountChangeColor;
}
if (source.title !== undefined) {
this.title = new StyledText(source.title);
}
if (source.clearAllButton !== undefined) {
this.clearAllButton = new ButtonConfiguration(source.clearAllButton);
}
if (source.barcodeItemTitle !== undefined) {
this.barcodeItemTitle = new StyledText(source.barcodeItemTitle);
}
if (source.barcodeItemSubtitle !== undefined) {
this.barcodeItemSubtitle = new StyledText(source.barcodeItemSubtitle);
}
if (source.barcodeItemImageVisible !== undefined) {
this.barcodeItemImageVisible = source.barcodeItemImageVisible;
}
if (source.submitButton !== undefined) {
this.submitButton = new ButtonConfiguration(source.submitButton);
}
if (source.startScanningButton !== undefined) {
this.startScanningButton = new ButtonConfiguration(source.startScanningButton);
}
if (source.placeholderTitle !== undefined) {
this.placeholderTitle = new StyledText(source.placeholderTitle);
}
if (source.placeholderSubtitle !== undefined) {
this.placeholderSubtitle = new StyledText(source.placeholderSubtitle);
}
if (source.placeholderIconBackground !== undefined) {
this.placeholderIconBackground = source.placeholderIconBackground;
}
if (source.placeholderIcon !== undefined) {
this.placeholderIcon = new IconStyle(source.placeholderIcon);
}
if (source.swipeToDelete !== undefined) {
this.swipeToDelete = new SwipeToDelete(source.swipeToDelete);
}
}
}
/**
Configuration of the mode for scanning multiple barcodes.
*/
export class MultipleScanningMode extends PartiallyConstructible {
public readonly _type: 'MultipleScanningMode' = 'MultipleScanningMode';
/**
Time interval in milliseconds before a barcode is counted again. 0 = no delay. The default value is 1000.
Default is 1000
*/
public countingRepeatDelay: number = 1000;
/**
Whether the user can submit an empty barcode list.
Default is false
*/
public allowEmptySubmission: boolean = false;
/**
Mode used for scanning multiple barcodes.
Default is COUNTING
*/
public mode: MultipleBarcodesScanningMode = 'COUNTING';
/**
Configuration of the preview mode for scanning multiple barcodes.
*/
public sheet: Sheet = new Sheet({
mode: 'COLLAPSED_SHEET',
collapsedVisibleHeight: 'SMALL',
listButton: new BadgedButton({
badgeBackgroundColor: '?sbColorSurface',
badgeForegroundColor: '?sbColorPrimary',
visible: true,
backgroundColor: '?sbColorSurfaceHigh',
foregroundColor: '?sbColorOnPrimary',
activeBackgroundColor: '?sbColorSurfaceHigh',
activeForegroundColor: '?sbColorOnPrimary',
}),
});
/**
Configuration of the list containing the barcodes that have already been scanned.
*/
public sheetContent: SheetContent = new SheetContent({
sheetColor: '?sbColorSurface',
dividerColor: '?sbColorOutline',
manualCountChangeEnabled: true,
manualCountOutlineColor: '?sbColorOutline',
manualCountChangeColor: '?sbColorPrimary',
title: new StyledText({ text: '?multipleModeSheetTitle', color: '?sbColorOnSurface' }),
clearAllButton: new ButtonConfiguration({
visible: true,
text: '?sheetClearAllButton',
background: new BackgroundStyle({
strokeColor: '#00000000',
fillColor: '#00000000',
strokeWidth: 1.0,
}),
foreground: new ForegroundStyle({
iconVisible: false,
color: '?sbColorOnSurface',
useShadow: false,
}),
}),
barcodeItemTitle: new StyledText({
visible: true,
text: 'BARCODE_TITLE',
color: '?sbColorOnSurface',
useShadow: false,
}),
barcodeItemSubtitle: new StyledText({
visible: true,
text: 'BARCODE_SUBTITLE',
color: '?sbColorOnSurfaceVariant',
useShadow: false,
}),
barcodeItemImageVisible: true,
submitButton: new ButtonConfiguration({
visible: true,
text: '?sheetSubmitButton',
background: new BackgroundStyle({
strokeColor: '#00000000',
fillColor: '#00000000',
strokeWidth: 1.0,
}),
foreground: new ForegroundStyle({
iconVisible: false,
color: '?sbColorOnSurface',
useShadow: false,
}),
}),
startScanningButton: new ButtonConfiguration({
visible: true,
text: '?sheetStartScanningButton',
background: new BackgroundStyle({
strokeColor: '?sbColorPrimary',
fillColor: '?sbColorPrimary',
strokeWidth: 1.0,
}),
foreground: new ForegroundStyle({
iconVisible: false,
color: '?sbColorOnPrimary',
useShadow: false,
}),
}),
placeholderTitle: new StyledText({
visible: true,
text: '?sheetPlaceholderTitle',
color: '?sbColorOnSurface',
useShadow: false,
}),
placeholderSubtitle: new StyledText({
visible: true,
text: '?sheetPlaceholderSubtitle',
color: '?sbColorOnSurfaceVariant',
useShadow: false,
}),
placeholderIconBackground: '?sbColorOutline',
placeholderIcon: new IconStyle({ visible: true, color: '?sbColorOnSurface' }),
swipeToDelete: new SwipeToDelete({
enabled: true,
backgroundColor: '?sbColorNegative',
iconColor: '?sbColorOnPrimary',
}),
});
/**
Configuration of the dialog to manually edit the barcode count.
*/
public manualCountEditDialog: ManualCountEditDialog = new ManualCountEditDialog({
sheetColor: '?sbColorSurface',
dividerColor: '?sbColorOutline',
modalOverlayColor: '?sbColorModalOverlay',
title: new StyledText({ text: '?manualCountEditDialogTitle', color: '?sbColorOnSurface' }),
info: new StyledText({ text: '?manualCountEditDialogInfo', color: '?sbColorOnSurfaceVariant' }),
updateButton: new ButtonConfiguration({
visible: true,
text: '?manualCountEditDialogUpdateButton',
background: new BackgroundStyle({
strokeColor: '?sbColorPrimary',
fillColor: '?sbColorPrimary',
strokeWidth: 1.0,
}),
foreground: new ForegroundStyle({
iconVisible: false,
color: '?sbColorOnPrimary',
useShadow: false,
}),
}),
cancelButton: new ButtonConfiguration({
visible: true,
text: '?manualCountEditDialogCancelButton',
background: new BackgroundStyle({
strokeColor: '#00000000',
fillColor: '#00000000',
strokeWidth: 1.0,
}),
foreground: new ForegroundStyle({
iconVisible: false,
color: '?sbColorPrimary',
useShadow: false,
}),
}),
clearTextButton: new IconStyle({ visible: true, color: '?sbColorOnSurfaceVariant' }),
});
/**
Appearance of the barcode info mapping.
*/
public barcodeInfoMapping: BarcodeInfoMapping = new BarcodeInfoMapping({
sheetColor: '?sbColorSurface',
dividerColor: '?sbColorOutline',
modalOverlayColor: '?sbColorModalOverlay',
loadingMessage: new StyledText({
text: '?barcodeInfoMappingLoadingMessage',
color: '?sbColorPrimary',
}),
errorState: new BarcodeItemErrorState({
title: new StyledText({
text: '?barcodeInfoMappingErrorStateTitle',
color: '?sbColorOnSurface',
}),
subtitle: new StyledText({
text: '?barcodeInfoMappingErrorStateSubtitle',
color: '?sbColorOnSurfaceVariant',
}),
retryButton: new ButtonConfiguration({
visible: true,
text: '?barcodeInfoMappingErrorStateRetryButton',
background: new BackgroundStyle({
strokeColor: '?sbColorPrimary',
fillColor: '?sbColorPrimary',
strokeWidth: 1.0,
}),
foreground: new ForegroundStyle({
iconVisible: true,
color: '?sbColorOnPrimary',
useShadow: false,
}),
}),
cancelButton: new ButtonConfiguration({
visible: true,
text: '?barcodeInfoMappingErrorStateCancelButton',
background: new BackgroundStyle({
strokeColor: '#00000000',
fillColor: '#00000000',
strokeWidth: 1.0,
}),
foreground: new ForegroundStyle({
iconVisible: false,
color: '?sbColorPrimary',
useShadow: false,
}),
}),
}),
});
/**
Configuration of the AR overlay.
*/
public arOverlay: ArOverlayGeneralConfiguration = new ArOverlayGeneralConfiguration({
visible: false,
counterBadge: new BadgeStyle({
visible: true,
background: new BackgroundStyle({
strokeColor: '#FF000000',
fillColor: '?sbColorPositive',
strokeWidth: 0.0,
}),
foregroundColor: '?sbColorOnSurface',
}),
automaticSelectionEnabled: false,
barcodeItemInfoPosition: 'BELOW',
polygon: new ArOverlayPolygonConfiguration({
visible: true,
deselected: new PolygonStyle({
strokeColor: '?sbColorSurface',
fillColor: '#00000000',
strokeWidth: 3.0,
cornerRadius: 5.0,
}),
selected: new PolygonStyle({
strokeColor: '?sbColorPositive',
fillColor: '#00000000',
strokeWidth: 3.0,
cornerRadius: 5.0,
}),
}),
barcodeItemConfiguration: new BarcodeItemConfiguration({
imageVisible: true,
titleSelected: new StyledText({ text: 'BARCODE_TITLE', color: '?sbColorOnSurface' }),
subtitleSelected: new StyledText({
visible: true,
text: 'BARCODE_SUBTITLE',
color: '?sbColorOnSurfaceVariant',
useShadow: false,
}),
titleDeselected: new StyledText({
visible: true,
text: 'BARCODE_TITLE',
color: '?sbColorOnSurface',
useShadow: false,
}),
subtitleDeselected: new StyledText({
text: 'BARCODE_SUBTITLE',
color: '?sbColorOnSurfaceVariant',
}),
backgroundSelected: new PolygonStyle({
strokeColor: '?sbColorPositive',
fillColor: '?sbColorPositive',
strokeWidth: 1.0,
cornerRadius: 5.0,
}),
backgroundDeselected: new PolygonStyle({
strokeColor: '?sbColorSurface',
fillColor: '?sbColorSurface',
strokeWidth: 1.0,
cornerRadius: 5.0,
}),
}),
});
/** @param source {@displayType `DeepPartial<MultipleScanningMode>`} */
public constructor(source: DeepPartial<MultipleScanningMode> = {}) {
super();
if (source.countingRepeatDelay !== undefined) {
this.countingRepeatDelay = source.countingRepeatDelay;
}
if (source.allowEmptySubmission !== undefined) {
this.allowEmptySubmission = source.allowEmptySubmission;
}
if (source.mode !== undefined) {
this.mode = source.mode;
}
if (source.sheet !== undefined) {
this.sheet = new Sheet(source.sheet);
}
if (source.sheetContent !== undefined) {
this.sheetContent = new SheetContent(source.sheetContent);
}
if (source.manualCountEditDialog !== undefined) {
this.manualCountEditDialog = new ManualCountEditDialog(source.manualCountEditDialog);
}
if (source.barcodeInfoMapping !== undefined) {
this.barcodeInfoMapping = new BarcodeInfoMapping(source.barcodeInfoMapping);
}
if (source.arOverlay !== undefined) {
this.arOverlay = new ArOverlayGeneralConfiguration(source.arOverlay);
}
}
}