barkoder-react-native
Version:
React native support for Barkoder - a Barcode Scanner SDK for the modern enterprise.
1,237 lines (1,156 loc) • 84.1 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.BarkoderView = exports.Barkoder = void 0;
var _react = _interopRequireDefault(require("react"));
var _reactNative = require("react-native");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const LINKING_ERROR = `The package 'barkoder-react-native' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({
ios: "- You have run 'pod install'\n",
default: ''
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
const OS_NOT_SUPPORTED = 'OS is not supported!';
const BARKODER_RESULT_EVENT_NAME = 'BarkoderResultEvent';
const BARKODER_CONFIG_EVENT_NAME = 'BarkoderConfigEvent';
const ComponentName = 'BarkoderReactNativeView';
const BarkoderReactNativeView = _reactNative.UIManager.getViewManagerConfig(ComponentName) != null ? (0, _reactNative.requireNativeComponent)(ComponentName) : () => {
throw new Error(LINKING_ERROR);
};
/**
* Initializes a new instance of the BarkoderView class.
*/
class BarkoderView extends _react.default.Component {
_myRef = /*#__PURE__*/_react.default.createRef();
_barkoder = new Barkoder(this._myRef);
_eventEmitter = new _reactNative.NativeEventEmitter(_reactNative.NativeModules.BarkoderEmitter);
constructor(props) {
super(props);
if (_reactNative.Platform.OS === 'ios') this.startConfigurationEmitter();else {
this._onDataReturned = this._onDataReturned.bind(this);
this._onBarkoderConfigCreated = this._onBarkoderConfigCreated.bind(this);
}
}
startConfigurationEmitter() {
this._eventEmitter.addListener(BARKODER_CONFIG_EVENT_NAME, () => {
this._eventEmitter.removeAllListeners(BARKODER_CONFIG_EVENT_NAME);
this.props.onBarkoderViewCreated(this._barkoder);
});
}
_onDataReturned(event) {
this._barkoder.onDataReturned(event);
}
_onBarkoderConfigCreated(_event) {
this.props.onBarkoderViewCreated(this._barkoder);
}
render() {
return /*#__PURE__*/_react.default.createElement(BarkoderReactNativeView, {
ref: this._myRef,
licenseKey: this.props.licenseKey,
style: this.props.style,
onBarkoderViewCreated: this.props.onBarkoderViewCreated,
onDataReturned: this._onDataReturned,
onBarkoderConfigCreated: this._onBarkoderConfigCreated
});
}
}
exports.BarkoderView = BarkoderView;
class Barkoder {
constructor(barkoderViewRef) {
this._barkoderViewRef = barkoderViewRef;
this._promisesMap = new Map();
this._promiseRequestId = 0;
this._eventEmitter = new _reactNative.NativeEventEmitter(_reactNative.NativeModules.BarkoderEmitter);
}
_dispatchCommand(commandID, commandArgs) {
_reactNative.UIManager.dispatchViewManagerCommand((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current), commandID, commandArgs);
}
// Used only for Android
onDataReturned(event) {
let nativeEvent = event.nativeEvent;
// 0 will be special case for scanning results
if (nativeEvent.promiseRequestId == 0) {
if (this._resultCallback) {
// Parse the payload as JSON before passing to BarkoderResult
const parsedPayload = typeof nativeEvent.payload === 'string' ? JSON.parse(nativeEvent.payload) : nativeEvent.payload;
this._resultCallback(new Barkoder.BarkoderResult(parsedPayload));
}
} else if (this._promisesMap.has(nativeEvent.promiseRequestId)) {
let [resolve, reject] = this._promisesMap.get(nativeEvent.promiseRequestId);
this._promisesMap.delete(nativeEvent.promiseRequestId);
if (nativeEvent.error) {
reject(new Barkoder.BarkoderError(nativeEvent.error));
} else {
resolve(nativeEvent.payload);
}
}
}
// Used only for iOS
startScanningEventEmmitter() {
this._eventEmitter.removeAllListeners(BARKODER_RESULT_EVENT_NAME);
this._eventEmitter.addListener(BARKODER_RESULT_EVENT_NAME, event => {
const {
data
} = event;
const result = new Barkoder.BarkoderResult(JSON.parse(data));
if (this._resultCallback) {
this._resultCallback(result);
}
});
}
/**
* Retrieves the maximum available zoom factor for the device's camera.
* @returns A promise that resolves with the maximum zoom factor.
*/
getMaxZoomFactor() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('getMaxZoomFactor', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.getMaxZoomFactor((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Sets the zoom factor for the device's camera, adjusting the level of zoom during barcode scanning.
* @param zoomFactor - The zoom factor to set.
*/
setZoomFactor(zoomFactor) {
this._dispatchCommand('setZoomFactor', [zoomFactor]);
}
/**
* Checks whether the device has a built-in flash (torch) that can be used for illumination during barcode scanning.
* @returns A promise that resolves with a boolean indicating whether flash is available.
*/
isFlashAvailable() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('isFlashAvailable', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.isFlashAvailable((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Enables or disables the device's flash (torch) for illumination during barcode scanning.
* @param enabled - A boolean indicating whether flash should be enabled.
*/
setFlashEnabled(enabled) {
this._dispatchCommand('setFlashEnabled', [enabled]);
}
/**
* Starts the camera for barcode scanning.
*/
startCamera() {
this._dispatchCommand('startCamera', []);
}
/**
* Halts the barcode scanning process, stopping the camera from capturing and processing barcode information.
*/
stopScanning() {
this._resultCallback = null;
this._eventEmitter.removeAllListeners(BARKODER_RESULT_EVENT_NAME);
this._dispatchCommand('stopScanning', []);
}
/**
* Initiates the barcode scanning process, allowing the application to detect and decode barcodes from the device's camera feed.
* @param resultsCallback - The callback function to handle barcode scanning events.
*/
startScanning(resultsCallback) {
if (this.isAndroid()) {
this._resultCallback = resultsCallback;
// 0 will be special case for scanning results
this._dispatchCommand('startScanning', [0]);
} else if (this.isIos()) {
this._resultCallback = resultsCallback;
this.startScanningEventEmmitter();
_reactNative.NativeModules.BarkoderReactNativeViewManager.startScanning((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Temporarily suspends the barcode scanning process, pausing the camera feed without completely stopping the scanning session.
*/
pauseScanning() {
this._resultCallback = null;
this._eventEmitter.removeAllListeners(BARKODER_RESULT_EVENT_NAME);
this._dispatchCommand('pauseScanning', []);
}
/**
* Scan barcodes from base64 string image
* @param base64 - image string.
* @param resultsCallback - The callback function to handle barcode scanning events.
*/
scanImage(base64, resultsCallback) {
if (this.isAndroid()) {
this._resultCallback = resultsCallback;
// 0 will be special case for scanning results
this._dispatchCommand('scanImage', [0, base64]);
} else if (this.isIos()) {
this._resultCallback = resultsCallback;
this.startScanningEventEmmitter();
_reactNative.NativeModules.BarkoderReactNativeViewManager.scanImage((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current), base64);
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Retrieves the resolution for barcode scanning.
* @returns A promise that resolves with the Barkoder resolution.
*/
getBarkoderResolution() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('getBarkoderResolution', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.getBarkoderResolution((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Sets the resolution for barcode scanning.
*/
setBarkoderResolution(barkoderResolution) {
this._dispatchCommand('setBarkoderResolution', [barkoderResolution]);
}
/**
* Sets the decoding speed for barcode scanning.
*/
setDecodingSpeed(decodingSpeed) {
this._dispatchCommand('setDecodingSpeed', [decodingSpeed]);
}
/**
* Sets the formatting type for barcode scanning.
*/
setFormattingType(formatting) {
this._dispatchCommand('setFormattingType', [formatting]);
}
/**
* Sets the encoding character set for barcode scanning.
* @param encodingCharacterSet - The encoding character set to be set.
*/
setEncodingCharacterSet(encodingCharacterSet) {
this._dispatchCommand('setEncodingCharacterSet', [encodingCharacterSet]);
}
/**
* Retrieves the hexadecimal color code representing the line color used to indicate the location of detected barcodes.
* @returns A promise that resolves with the location line color in hexadecimal format.
*/
getLocationLineColorHex() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('getLocationLineColorHex', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.getLocationLineColorHex((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Sets the color of the lines used to indicate the location of detected barcodes on the camera feed.
* @param hexColor - The hexadecimal color value to set.
* @returns A promise that resolves with a boolean indicating whether the color was successfully set.
*/
setLocationLineColor(hexColor) {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('setLocationLineColor', [promiseRequestId, hexColor]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.setLocationLineColor((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current), hexColor);
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Retrieves the current width setting for the lines indicating the location of detected barcodes on the camera feed.
* @returns A promise that resolves with the location line width.
*/
getLocationLineWidth() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('getLocationLineWidth', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.getLocationLineWidth((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Sets the width of the lines indicating the location of detected barcodes on the camera feed.
* @param lineWidth - The width of the location line to set.
*/
setLocationLineWidth(lineWidth) {
this._dispatchCommand('setLocationLineWidth', [lineWidth]);
}
/**
* Retrieves the hexadecimal color code representing the line color of the Region of Interest (ROI) on the camera preview.
* @returns A promise that resolves with the ROI line color in hexadecimal format.
*/
getRoiLineColorHex() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('getRoiLineColorHex', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.getRoiLineColorHex((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Sets the color of the lines outlining the Region of Interest (ROI) for barcode scanning on the camera feed.
* @param hexColor - The hexadecimal representation of the color.
* @returns A promise that resolves with a boolean indicating whether the color was successfully set.
*/
setRoiLineColor(hexColor) {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('setRoiLineColor', [promiseRequestId, hexColor]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.setRoiLineColor((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current), hexColor);
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Retrieves the current width setting for the lines outlining the Region of Interest (ROI) on the camera preview.
* @returns A promise that resolves with the ROI line width.
*/
getRoiLineWidth() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('getRoiLineWidth', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.getRoiLineWidth((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Sets the width of the lines outlining the Region of Interest (ROI) for barcode scanning on the camera feed.
* @param lineWidth - The width of the ROI line to set.
*/
setRoiLineWidth(lineWidth) {
this._dispatchCommand('setRoiLineWidth', [lineWidth]);
}
/**
* Retrieves the hexadecimal color code representing the background color of the overlay within the Region of Interest (ROI) on the camera preview.
* @returns A promise that resolves with the ROI overlay background color in hexadecimal format.
*/
getRoiOverlayBackgroundColorHex() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('getRoiOverlayBackgroundColorHex', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.getRoiOverlayBackgroundColorHex((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Sets the background color of the overlay within the Region of Interest (ROI) for barcode scanning on the camera feed.
* @param hexColor - The hexadecimal color value to set for the ROI overlay background.
* @returns A promise that resolves with a boolean indicating whether the color was successfully set.
*/
setRoiOverlayBackgroundColor(hexColor) {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('setRoiOverlayBackgroundColor', [promiseRequestId, hexColor]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.setRoiOverlayBackgroundColor((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current), hexColor);
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Checks if the session is closed on result enabled.
* @returns A promise that resolves with a boolean indicating whether close session on result is enabled.
*/
isCloseSessionOnResultEnabled() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('isCloseSessionOnResultEnabled', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.isCloseSessionOnResultEnabled((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Enables or disables the automatic closing of the scanning session upon detecting a barcode result.
* @param enabled - A boolean indicating whether to enable close session on result.
*/
setCloseSessionOnResultEnabled(enabled) {
this._dispatchCommand('setCloseSessionOnResultEnabled', [enabled]);
}
/**
* Checks if image result is enabled.
* @returns A promise that resolves with a boolean indicating whether image result is enabled.
*/
isImageResultEnabled() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('isImageResultEnabled', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.isImageResultEnabled((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Enables or disables the capturing and processing of image data when a barcode is successfully detected.
* @param enabled - True to enable image result display, false to disable it.
*/
setImageResultEnabled(enabled) {
this._dispatchCommand('setImageResultEnabled', [enabled]);
}
/**
* Checks if location in image result is enabled.
* @returns A promise that resolves with a boolean indicating whether location in image result is enabled.
*/
isLocationInImageResultEnabled() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('isLocationInImageResultEnabled', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.isLocationInImageResultEnabled((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Enables or disables the inclusion of barcode location information within the image data result.
* @param enabled - True to display the location, false to hide it.
*/
setLocationInImageResultEnabled(enabled) {
this._dispatchCommand('setLocationInImageResultEnabled', [enabled]);
}
/**
* Retrieves the region of interest (ROI).
* @returns A promise that resolves with an array representing the region of interest (ROI).
*/
getRegionOfInterest() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('getRegionOfInterest', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.getRegionOfInterest((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Defines the Region of Interest (ROI) on the camera preview for barcode scanning, specifying an area where the application focuses on detecting barcodes.
* @param left - The left coordinate of the ROI.
* @param top - The top coordinate of the ROI.
* @param width - The width of the ROI.
* @param height - The height of the ROI.
* @returns A promise that resolves with a boolean indicating whether the ROI was successfully set.
*/
setRegionOfInterest(left, top, width, height) {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('setRegionOfInterest', [promiseRequestId, left, top, width, height]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.setRegionOfInterest((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current), left, top, width, height);
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Retrieves the threads limit.
* @returns {Promise<number>} A promise that resolves with the threads limit.
*/
getThreadsLimit() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('getThreadsLimit', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.getThreadsLimit((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Sets the threads limit.
* @param threadsLimit - The limit for the number of threads to set.
* @returns {Promise<boolean>} A promise that resolves with a boolean indicating whether the threads limit was successfully set.
*/
setThreadsLimit(threadsLimit) {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('setThreadsLimit', [promiseRequestId, threadsLimit]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.setThreadsLimit((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current), threadsLimit);
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Checks if location in preview is enabled.
* @returns {Promise<boolean>} A promise that resolves with a boolean indicating whether location in preview is enabled.
*/
isLocationInPreviewEnabled() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('isLocationInPreviewEnabled', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.isLocationInPreviewEnabled((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Enables or disables the display of barcode location information on the camera preview.
* @param enabled - True to display the location, false to hide it.
*/
setLocationInPreviewEnabled(enabled) {
this._dispatchCommand('setLocationInPreviewEnabled', [enabled]);
}
/**
* Checks if pinch to zoom is enabled.
* @returns {Promise<boolean>} A promise that resolves with a boolean indicating whether pinch to zoom is enabled.
*/
isPinchToZoomEnabled() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('isPinchToZoomEnabled', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.isPinchToZoomEnabled((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Enables or disables the pinch-to-zoom feature for adjusting the zoom level during barcode scanning.
* @param enabled - True to enable pinch-to-zoom, false to disable it.
*/
setPinchToZoomEnabled(enabled) {
this._dispatchCommand('setPinchToZoomEnabled', [enabled]);
}
/**
* Checks if the region of interest (ROI) is visible.
* @returns {Promise<boolean>} A promise that resolves with a boolean indicating whether the ROI is visible.
*/
isRegionOfInterestVisible() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('isRegionOfInterestVisible', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.isRegionOfInterestVisible((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Sets the visibility of the Region of Interest (ROI) on the camera preview.
* @param visible - True to make the ROI visible, false to hide it.
*/
setRegionOfInterestVisible(visible) {
this._dispatchCommand('setRegionOfInterestVisible', [visible]);
}
/**
* Retrieves the value indicating whether a beep sound is played on successful barcode scanning.
* @returns {Promise<boolean>} A promise that resolves with a boolean indicating whether the beep on success is enabled.
*/
isBeepOnSuccessEnabled() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('isBeepOnSuccessEnabled', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.isBeepOnSuccessEnabled((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Enables or disables the audible beep sound upon successfully decoding a barcode.
* @param enabled - True to enable beep sound, false to disable it.
*/
setBeepOnSuccessEnabled(enabled) {
this._dispatchCommand('setBeepOnSuccessEnabled', [enabled]);
}
/**
* Retrieves the value indicating whether vibration is enabled on successful barcode scanning.
* @returns {Promise<boolean>} A promise that resolves with a boolean indicating whether vibrate on success is enabled.
*/
isVibrateOnSuccessEnabled() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('isVibrateOnSuccessEnabled', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.isVibrateOnSuccessEnabled((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Enables or disables the vibration on successful barcode scanning.
* @param enabled - True to enable vibration, false to disable it.
*/
setVibrateOnSuccessEnabled(enabled) {
this._dispatchCommand('setVibrateOnSuccessEnabled', [enabled]);
}
/**
* Retrieves the character set used for encoding barcode data.
* @returns {Promise<string>} A promise that resolves with the encoding character set.
*/
getEncodingCharacterSet() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('getEncodingCharacterSet', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.getEncodingCharacterSet((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Retrieves the version of the Barkoder library.
* @returns {Promise<string>} A promise that resolves with the version of the Barkoder library.
*/
getVersion() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('getVersion', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.getVersion((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Retrieves the current decoding speed setting for barcode scanning.
* @returns {Promise<Barkoder.DecodingSpeed>} A promise that resolves with the decoding speed configuration.
*/
getDecodingSpeed() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('getDecodingSpeed', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.getDecodingSpeed((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Retrieves the formatting type used for presenting decoded barcode data..
* @returns {Promise<Barkoder.FormattingType>} A promise that resolves with the formatting type configuration.
*/
getFormattingType() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('getFormattingType', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.getFormattingType((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Checks if a specific barcode type is enabled.
* @param barcodeType - The barcode type to check.
* @returns {Promise<boolean>} A promise that resolves with a boolean indicating whether the barcode type is enabled.
*/
isBarcodeTypeEnabled(barcodeType) {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('isBarcodeTypeEnabled', [promiseRequestId, barcodeType]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.isBarcodeTypeEnabled((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current), barcodeType);
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Retrieves the length range of the specified barcode type.
* @param barcodeType - The barcode type to get the length range for.
* @returns {Promise<number[]>} A promise that resolves with an array representing the length range of the barcode type.
*/
getBarcodeTypeLengthRange(barcodeType) {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('getBarcodeTypeLengthRange', [promiseRequestId, barcodeType]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.getBarcodeTypeLengthRange((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current), barcodeType);
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Sets the length range for the specified barcode type.
* @param barcodeType - The barcode type to set the length range for.
* @param min - The minimum length of the barcode type.
* @param max - The maximum length of the barcode type.
* @returns {Promise<boolean>} A promise that resolves with a boolean indicating whether the length range was successfully set.
*/
setBarcodeTypeLengthRange(barcodeType, min, max) {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('setBarcodeTypeLengthRange', [promiseRequestId, barcodeType, min, max]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.setBarcodeTypeLengthRange((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current), barcodeType, min, max);
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Configures the Barkoder functionality based on the provided configuration.
* @param barkoderConfig - The configuration parameters for the Barkoder.
* @returns {Promise<boolean>} A promise that resolves with a boolean indicating whether the configuration was successful.
*/
configureBarkoder(barkoderConfig) {
const jsonString = barkoderConfig.toJsonString();
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('configureBarkoder', [promiseRequestId, jsonString]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.configureBarkoder((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current), jsonString);
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Enables or disables the specified barcode type for scanning.
* @param barcodeType - The barcode type to enable or disable.
* @param enabled - True to enable the barcode type, false to disable it.
*/
setBarcodeTypeEnabled(barcodeType, enabled) {
this._dispatchCommand('setBarcodeTypeEnabled', [barcodeType, enabled]);
}
/**
* Retrieves the MSI checksum type.
* @returns {Promise<Barkoder.MsiChecksumType>} A promise that resolves with the checksum type for MSI barcodes.
*/
getMsiChecksumType() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('getMsiChecksumType', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.getMsiChecksumType((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Set the MSI checksum type.
* @param msiChecksumType - The MSI checksum type to set.
*/
setMsiChecksumType(msiChecksumType) {
this._dispatchCommand('setMsiChecksumType', [msiChecksumType]);
}
/**
* Retrieves the checksum type for Code 39 barcodes.
* @returns {Promise<Barkoder.Code39ChecksumType>} A promise that resolves with the checksum type for Code 39 barcodes.
*/
getCode39ChecksumType() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('getCode39ChecksumType', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.getCode39ChecksumType((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Sets the checksum type for Code 39 barcodes.
* @param code39ChecksumType - The checksum type to set for Code 39 barcodes.
*/
setCode39ChecksumType(code39ChecksumType) {
this._dispatchCommand('setCode39ChecksumType', [code39ChecksumType]);
}
/**
* Retrieves the Code11 checksum type.
* @returns {Promise<Barkoder.Code11ChecksumType>} A promise that resolves with the checksum type for Code 11 barcodes.
*/
getCode11ChecksumType() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('getCode11ChecksumType', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.getCode11ChecksumType((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Sets the checksum type for Code 11 barcodes.
* @param code11ChecksumType - The checksum type to set for Code 11 barcodes.
*/
setCode11ChecksumType(code11ChecksumType) {
this._dispatchCommand('setCode11ChecksumType', [code11ChecksumType]);
}
/**
* Sets the maximum number of results to be returned from barcode scanning.
* @param maximumResultsCount - The maximum number of results to return.
*/
setMaximumResultsCount(maximumResultsCount) {
this._dispatchCommand('setMaximumResultsCount', [maximumResultsCount]);
}
/**
* Sets the delay in milliseconds for considering duplicate barcodes during scanning.
* @param duplicatesDelayMs - The delay in milliseconds for duplicate detection.
*/
setDuplicatesDelayMs(duplicatesDelayMs) {
this._dispatchCommand('setDuplicatesDelayMs', [duplicatesDelayMs]);
}
/**
* Sets the caching duration (in milliseconds) for multi-code results.
* @param multicodeCachingDuration - The caching duration (in milliseconds) for multi-code results.
*/
setMulticodeCachingDuration(multicodeCachingDuration) {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('setMulticodeCachingDuration', [promiseRequestId, multicodeCachingDuration]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.setMulticodeCachingDuration((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current), multicodeCachingDuration);
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Sets whether multi-code caching is enabled.
* @param multicodeCachingEnabled - A boolean indicating whether to enable multi-code caching.
*/
setMulticodeCachingEnabled(multicodeCachingEnabled) {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('setMulticodeCachingEnabled', [promiseRequestId, multicodeCachingEnabled]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.setMulticodeCachingEnabled((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current), multicodeCachingEnabled);
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Gets the maximum number of results to be returned from barcode scanning.
* @returns {Promise<number>} A promise that resolves with the maximum number of results to return.
*/
getMaximumResultsCount() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('getMaximumResultsCount', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.getMaximumResultsCount((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Gets the delay in milliseconds for considering duplicate barcodes during scanning.
* @returns {Promise<number>} A promise that resolves with the delay (in milliseconds) for detecting duplicate results.
*/
getDuplicatesDelayMs() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('getDuplicatesDelayMs', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.getDuplicatesDelayMs((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Retrieves whether Direct Part Marking (DPM) mode for Datamatrix barcodes is enabled
* @returns {Promise<boolean>} A promise that resolves with a boolean indicating whether DPM mode for Datamatrix barcodes is enabled.
*/
isDatamatrixDpmModeEnabled() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('isDatamatrixDpmModeEnabled', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.isDatamatrixDpmModeEnabled((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Sets whether the Direct Part Marking (DPM) mode for Datamatrix barcodes is enabled.
* @param enabled - True to enable DPM mode, false to disable it.
*/
setDatamatrixDpmModeEnabled(enabled) {
this._dispatchCommand('setDatamatrixDpmModeEnabled', [enabled]);
}
/**
* Retrieves whether Direct Part Marking (DPM) mode for QR barcodes is enabled
* @returns {Promise<boolean>} A promise that resolves with a boolean indicating whether DPM mode for QR barcodes is enabled.
*/
isQrDpmModeEnabled() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('isQrDpmModeEnabled', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.isQrDpmModeEnabled((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Sets whether the Direct Part Marking (DPM) mode for QR barcodes is enabled.
* @param enabled - True to enable DPM mode, false to disable it.
*/
setQrDpmModeEnabled(enabled) {
this._dispatchCommand('setQrDpmModeEnabled', [enabled]);
}
/**
* Retrieves whether Direct Part Marking (DPM) mode for QR Micro barcodes is enabled
* @returns {Promise<boolean>} A promise that resolves with a boolean indicating whether DPM mode for QR Micro barcodes is enabled.
*/
isQrMicroDpmModeEnabled() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('isQrMicroDpmModeEnabled', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.isQrMicroDpmModeEnabled((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Sets whether the Direct Part Marking (DPM) mode for QR Micro barcodes is enabled.
* @param enabled - True to enable DPM mode, false to disable it.
*/
setQrMicroDpmModeEnabled(enabled) {
this._dispatchCommand('setQrMicroDpmModeEnabled', [enabled]);
}
/**
* Retrieves whether Master checksum is enabled when scanning ID Documents
* @returns {Promise<boolean>} A promise that resolves with a boolean indicating whether Master checksum is enabled when scanning ID Documents
*/
isIdDocumentMasterChecksumEnabled() {
if (this.isAndroid()) {
let promisesMap = this._promisesMap;
let promiseRequestId = ++this._promiseRequestId;
let promise = new Promise((resolve, reject) => {
promisesMap.set(promiseRequestId, [resolve, reject]);
});
this._dispatchCommand('isIdDocumentMasterChecksumEnabled', [promiseRequestId]);
return promise;
} else if (this.isIos()) {
return _reactNative.NativeModules.BarkoderReactNativeViewManager.isIdDocumentMasterChecksumEnabled((0, _reactNative.findNodeHandle)(this._barkoderViewRef.current));
} else {
throw new Error(OS_NOT_SUPPORTED);
}
}
/**
* Sets whether Master checksum should be requiered when scanning ID Documents
* @param enabled - True to enable Master checksum, false to disable it.
*/
setIdDocumentMasterChecksumEnabled(enabled) {
this._dispatchCommand('setIdDocumentMasterChecksumEnabled', [enabled]);
}
/**
* Gets the value indicating whether deblurring is enabled for UPC/EAN barcodes.
* @returns {Promise<boolean>} A promise that resolves with a boolean indicating whether the deblurring feature for UPC/EAN barcodes is enabled.
*/
isUpcEanDeblurEnabled() {
if (this