react-native-scanbot-sdk
Version:
Scanbot Document and Barcode Scanner SDK React Native Plugin for Android and iOS
154 lines (146 loc) • 4.89 kB
text/typescript
import { BackgroundStyle } from '../common/Common';
import { BarcodeItemMapper } from '../BarcodeItemMapper';
import { ButtonConfiguration } from '../common/Common';
import { DeepPartial, PartiallyConstructible } from '../../utils';
import { ForegroundStyle } from '../common/Common';
import { StyledText } from '../common/Common';
/**
Configuration of the the mapper's error dialog.
*/
export class BarcodeItemErrorState extends PartiallyConstructible {
/**
Title displayed above the error message.
*/
public title: StyledText = new StyledText({
text: 'Connection Error!',
color: '?sbColorOnSurface',
});
/**
Error message.
*/
public subtitle: StyledText = new StyledText({
text: 'There was an issue and the data requested was not fetched. You could try again or discard this result to start a new scan.',
color: '?sbColorOnSurfaceVariant',
});
/**
Configuration of the retry button.
*/
public retryButton: ButtonConfiguration = new ButtonConfiguration({});
/**
Configuration of the cancel button.
*/
public cancelButton: ButtonConfiguration = new ButtonConfiguration({});
/** @param source {@displayType `DeepPartial<BarcodeItemErrorState>`} */
public constructor(source: DeepPartial<BarcodeItemErrorState> = {}) {
super();
if (source.title !== undefined) {
this.title = new StyledText(source.title);
}
if (source.subtitle !== undefined) {
this.subtitle = new StyledText(source.subtitle);
}
if (source.retryButton !== undefined) {
this.retryButton = new ButtonConfiguration(source.retryButton);
}
if (source.cancelButton !== undefined) {
this.cancelButton = new ButtonConfiguration(source.cancelButton);
}
}
}
/**
Format of the mapped barcode data.
*/
export class BarcodeMappedData extends PartiallyConstructible {
/**
Title of the barcode.
*/
public title: string;
/**
Subtitle of the barcode.
*/
public subtitle: string;
/**
Image of the barcode.
*/
public barcodeImage: string;
/**
Use this key to display the original barcode image
*/
public static readonly barcodeImageKey = 'BARCODE_IMAGE';
/** @param source {@displayType `DeepPartial<BarcodeMappedData>`} */
public constructor(source: DeepPartial<BarcodeMappedData> = {}) {
super();
if (source.title !== undefined) {
this.title = source.title;
} else {
throw new Error('title must be present in constructor argument');
}
if (source.subtitle !== undefined) {
this.subtitle = source.subtitle;
} else {
throw new Error('subtitle must be present in constructor argument');
}
if (source.barcodeImage !== undefined) {
this.barcodeImage = source.barcodeImage;
} else {
throw new Error('barcodeImage must be present in constructor argument');
}
}
}
/**
Configuration of the barcode data mapping.
*/
export class BarcodeInfoMapping extends PartiallyConstructible {
/**
Callback to map the barcode data to the data of the corresponding product.
*/
public barcodeItemMapper: BarcodeItemMapper | null = null;
/**
Background color of the barcode info dialog.
Default is "?sbColorSurface"
*/
public sheetColor: string = '?sbColorSurface';
/**
Color of the divider and separator lines in the barcode info dialog.
Default is "?sbColorOutline"
*/
public dividerColor: string = '?sbColorOutline';
/**
Background color of the overlay surrounding the barcode mapping error dialog.
Default is "?sbColorModalOverlay"
*/
public modalOverlayColor: string = '?sbColorModalOverlay';
/**
Text being displayed while a barcode is being mapped.
*/
public loadingMessage: StyledText = new StyledText({
text: 'Loading message for barcode info mapping.',
color: '?sbColorPrimary',
});
/**
Configuration of the error state displayed when processing a barcode fails.
*/
public errorState: BarcodeItemErrorState = new BarcodeItemErrorState({});
/** @param source {@displayType `DeepPartial<BarcodeInfoMapping>`} */
public constructor(source: DeepPartial<BarcodeInfoMapping> = {}) {
super();
if (source.barcodeItemMapper !== undefined) {
this.barcodeItemMapper = source.barcodeItemMapper != null ? source.barcodeItemMapper : null;
}
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.loadingMessage !== undefined) {
this.loadingMessage = new StyledText(source.loadingMessage);
}
if (source.errorState !== undefined) {
this.errorState = new BarcodeItemErrorState(source.errorState);
}
}
}