Skip to main content

React Native API

API Reference

All functions are asynchronous. All functions will, at a minimum, include a promise parameter, which will return the success or failure result of the Java/Kotlin function.

  • promise will be returned in most cases, and will return the same value as the standard Java/Kotlin function would.

Namespaces

NamespaceDescription
BarcodeManagerreceive barcode data
AutoScanTriggerwork the autoscan features
KeyboardManagerset usable device triggers
LedManagercontrol device LEDs
ScannerPropertiesdefine available symbologies

BarcodeManager


FunctionDescription
addReadListenerRegister to receive barcode data on each scan.
releaseCall to remove all listeners from BarcodeManager.
pressTriggerSimulate a trigger button press.
releaseTriggerSimulate a trigger button release.

.addReadListener(promise): number

Register to receive barcode data on each scan. The callback you send to the NativeEventEmitter (see example below) will be called every time a barcode is successfully scanned. Therefore, you will typically only need to call barcodeManager.addReadListener() once in your application.

Response
{
"barcodeData": "EUG2997",
"barcodeType": "CODE128"
}
Example
import { NativeEventEmitter, Alert } from 'react-native';
import { BarcodeManager } from '@datalogic/react-native-datalogic-module';
...
const eventEmitter = new NativeEventEmitter(BarcodeManager);
eventEmitter.addListener('successCallback', map => {
Alert.alert('Barcode Result', map.barcodeData + '\n' + map.barcodeType);
});
BarcodeManager.addReadListener();

.release(promise): number

Call to remove all registered listeners to the BarcodeManager.

Response

number with SUCCESS (0) in case of success, otherwise a possible error code, matching one of the DecodeException error constants.

Example
import { NativeEventEmitter } from 'react-native';
import { BarcodeManager } from '@datalogic/react-native-datalogic-module';
...
React.useEffect(() => {
let nativeListenerReturn = null;
try {
const eventEmitter = new NativeEventEmitter(BarcodeManager);
nativeListenerReturn = eventEmitter.addListener(...);
BarcodeManager.addReadListener();
} catch (e) {
console.error(e);
}

return () => {
nativeListenerReturn.remove();
BarcodeManager.release();
};
}, []);

.pressTrigger(promise): number

Call this method to simulate a trigger button press. The method does not always immediately start a capture; instead it behaves like pressing a physical scan button.

Response

number with SUCCESS (0) in case of success, otherwise a possible error code, matching one of the DecodeException error constants.

Example
import { BarcodeManager } from '@datalogic/react-native-datalogic-module';
...
var triggerReturn = await BarcodeManager.pressTrigger();
if (triggerReturn === 0) {
console.log('Press Trigger Success');
} else {
console.log('Press Trigger Failure: ' + triggerReturn);
}

.releaseTrigger(promise): number

Call this method to simulate a release of a trigger button. The method does not always immediately stop a capture; instead it behaves like releasing a physical scan button.

Response

number with SUCCESS (0) in case of success, otherwise a possible error code, matching one of the DecodeException error constants.

Example
import { BarcodeManager } from '@datalogic/react-native-datalogic-module';
...
var triggerReturn = await BarcodeManager.releaseTrigger();
if (triggerReturn === 0) {
console.log('Release Trigger Success');
} else {
console.log('Release Trigger Failure: ' + triggerReturn);
}

AutoScanTrigger


FunctionDescription
isAvailableDetermine if the auto scan feature is available on this device.
getSupportedRangesGet the supported ranges of the autoscan feature.
getCurrentRangeGet the current range of the autoscan feature.
setCurrentRangeSet the current range of the autoscan feature.

.isAvailable(promise): boolean

Determine if the auto scan feature is available on this device.

Response
  • boolean - indicates if autoscan is supported or not on this device.
Example
import { AutoScanTrigger } from '@datalogic/react-native-datalogic-module';
...
var isAvailableReturn = await AutoScanTrigger.isAvailable();
console.log(isAvailableReturn);

.getSupportedRanges(promise): Object

Get the supported ranges of the autoscan feature.

Response

supportedRanges : Object - provides array of ranges device supports. The array will be null if device does not support autoscan. Each object in the array contains:

  • id : number - unique value for a step in the supported ranges
  • name : string - descriptive text related to the id

If AutoScan is not supported by device:

null

If AutoScan is supported:

{
"supportedRanges":[
{
"id":0,
"name":"Near"
},
{
"id":1,
"name":"Intermediate"
},
{
"id":2,
"name":"Far"
}
]
}
Example
import { AutoScanTrigger } from '@datalogic/react-native-datalogic-module';
...
var supportedRangesReturn = await AutoScanTrigger.getSupportedRanges();
console.log(supportedRangesReturn);

.getCurrentRange(promise): Object

Get the current range of the autoscan feature.

Response

currentRange : object - contains 2 fields:

  • id : number
  • name : string

If AutoScan is not supported by device:

null

If AutoScan is supported:

{
"currentRange":
{
"id":1,
"name":"Intermediate"
}
}
Example
import { AutoScanTrigger } from '@datalogic/react-native-datalogic-module';
...
var currentRangeReturn = await AutoScanTrigger.getCurrentRange();
console.log(currentRangeReturn);

.setCurrentRange(rangeId, promise): boolean

Set the current range of the autoscan feature.

rangeId : number - should match one of the id values retrieved by the getSupportedRanges function.

Response

Boolean with true or false depending on success.

Example

Set current range to "Intermediate"

var setRangeReturn = await AutoScanTrigger.setCurrentRange(0);
console.log(setRangeReturn);

KeyboardManager


FunctionDescription
getAllAvailableTriggersGet all the available triggers of the device.
setAllAvailableTriggersSet all the devices triggers on or off.
setTriggersSet one or more triggers on or off.

.getAllAvailableTriggers (promise): Object

Get all the available triggers of the device.

Response

triggers : Object - each Object in the triggers Object contains:

  • enabled : boolean
  • id : number
  • name : string

Typical response:

{
"triggers":[
{
"enabled":true,
"id":0,
"name":"Left Trigger"
},
{
"enabled":false,
"id":1,
"name":"Right Trigger"
},
{
"enabled":false,
"id":2,
"name":"Pistol Trigger"
}
]
}
Example
var getTriggersReturn = await KeyboardManager.getAllAvailableTriggers();
console.log(getTriggersReturn);

.setAllAvailableTriggers(enable, promise): boolean

Set all the devices triggers on or off.

Response

boolean with true/false based on success

Example

Turn all triggers on.

var setTriggersReturn = await KeyboardManager.setAllAvailableTriggers(
true
);
console.log(setTriggersReturn);

.setTriggers(config, promise): boolean

Set one or more triggers on or off. You will likely call getAllAvailableTriggers, edit the enabled flags of each returned object as desired, and then resubmit by calling setTriggers.

config : Object - each object in the array represents an individual trigger. Each object in the array contains:

  • id : number
  • enabled : boolean
Response

boolean with true/false based on success.

Example
var triggersArray = [
{ enabled: false, id: 0, name: 'Left Trigger' },
{ enabled: true, id: 1, name: 'Right Trigger' },
{ enabled: false, id: 2, name: 'Pistol Trigger' },
];
var setTriggersReturn = await KeyboardManager.setTriggers(triggersArray);
console.log(setTriggersReturn);

LedManager


FunctionDescription
setLedSet various device LEDs.

.setLed(object, promise): boolean

Set the various device LEDs. A list of enum values for LEDs can be found here.

Response

boolean with true/false based on success.

Example
var ledMap = { led: 'LED_GREEN_SPOT', enable: false };
var setLedReturn = await LedManager.setLed(ledMap);
console.log(setLedReturn);

ScannerProperties


FunctionDescription
editGet a list of supported properties along with the state of each (enabled or disabled).
storeApply changes to one or more properties with the values supplied.

.edit(promise): Object

Get a list of supported scanner properties along with the state of each (enabled or disabled).

Response

A single Object containing Objects for each of the available symbologies. Each symbology contains, at a minimum, these fields:

  • enable : boolean - if scanner is set to detect this barcode type or not
  • supported : boolean - if the scanner supports the given barcode type or not
{
"keyboardWedge":{"enable":true,"supported":true},
"aztec":{"enable":true,"supported":true},
"codabar":{"enable":true,"supported":true},
"code128":{"enable":true,"supported":true},
"code39":{"enable":true,"supported":true},
"code93":{"enable":false,"supported":true},
"composite":{"enable":false,"supported":true},
"datamatrix":{"enable":true,"supported":true},
"digimarc":{"enable":false,"supported":false},
"discrete25":{"enable":false,"supported":true},
"ean13":{"enable":true,"supported":true},
"ean8":{"enable":true,"supported":true},
"gs1DataBar_14":{"enable":true,"supported":true},
"gs1DataBar_Expanded":{"enable":true,"supported":true},
"gs1DataBar_Limited":{"enable":true,"supported":true},
"interleaved25":{"enable":true,"supported":true},
"matrix25":{"enable":false,"supported":true},
"maxicode":{"enable":false,"supported":true},
"microQr":{"enable":false,"supported":true},
"micropdf417":{"enable":false,"supported":true},
"msi":{"enable":false,"supported":true},
"p4State":{"enable":false,"supported":true},
"pAus":{"enable":false,"supported":true},
"pJap":{"enable":false,"supported":true},
"pKix":{"enable":false,"supported":true},
"pPlanet":{"enable":false,"supported":true},
"pPostnet":{"enable":false,"supported":true},
"pRM":{"enable":false,"supported":true},
"pdf417":{"enable":true,"supported":true},
"qrCode":{"enable":true,"supported":true},
"upcA":{"enable":true,"supported":true},
"upcE":{"enable":true,"supported":true}
}
Example
var editReturn = await ScannerProperties.edit();
console.log(JSON.stringify(editReturn, undefined, 1));

.store(properties, promise): boolean

Apply changes to one or more symbologies with the values supplied in properties.

Response

boolean with true/false based on success.

Examples

Disable keyboardWedge symbology, enable aztec symbology.

var storeMap = {
keyboardWedge: { enable: false, supported: true },
aztec: { enable: true },
};
var storeReturn = await ScannerProperties.store(storeMap);
console.log(JSON.stringify(storeReturn, undefined, 1));