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.
promisewill be returned in most cases, and will return the same value as the standard Java/Kotlin function would.
Namespaces
| Namespace | Description |
|---|---|
| BarcodeManager | receive barcode data |
| AutoScanTrigger | work the autoscan features |
| KeyboardManager | set usable device triggers |
| LedManager | control device LEDs |
| ScannerProperties | define available symbologies |
BarcodeManager
| Function | Description |
|---|---|
| addReadListener | Register to receive barcode data on each scan. |
| release | Call to remove all listeners from BarcodeManager. |
| pressTrigger | Simulate a trigger button press. |
| releaseTrigger | Simulate 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:string- the barcode data scanned.barcodeType:string- will be one of theBarcodeIDvalues defined in the BarcodeID class in the Datalogic Android SDK.
{
"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
| Function | Description |
|---|---|
| isAvailable | Determine if the auto scan feature is available on this device. |
| getSupportedRanges | Get the supported ranges of the autoscan feature. |
| getCurrentRange | Get the current range of the autoscan feature. |
| setCurrentRange | Set 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 rangesname:string- descriptive text related to theid
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:numbername: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
| Function | Description |
|---|---|
| getAllAvailableTriggers | Get all the available triggers of the device. |
| setAllAvailableTriggers | Set all the devices triggers on or off. |
| setTriggers | Set 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:booleanid:numbername: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:numberenabled: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
| Function | Description |
|---|---|
| setLed | Set 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
| Function | Description |
|---|---|
| edit | Get a list of supported properties along with the state of each (enabled or disabled). |
| store | Apply 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 notsupported: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));