forked from jolupara25/RN-HBR-todoboletos-QR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (39 loc) · 1.46 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const ReactNative = require('react-native');
const {NativeModules, DeviceEventEmitter, NativeEventEmitter} = ReactNative;
const HoneywellBarcodeReader = NativeModules.HoneywellBarcodeReader || {}; // Hacky fallback for iOS
/**
* Listen for available events
* @param {String} eventName Name of event one of barcodeReadSuccess, barcodeReadFail
* @param {Function} handler Event handler
*/
const barcodeReaderEmitter = new NativeEventEmitter();
var subscriptionBarcodeReadSuccess = null;
var subscriptionBarcodeReadFail = null;
HoneywellBarcodeReader.onBarcodeReadSuccess = handler => {
subscriptionBarcodeReadSuccess?.remove();
subscriptionBarcodeReadSuccess = null;
subscriptionBarcodeReadSuccess = barcodeReaderEmitter.addListener(
HoneywellBarcodeReader.BARCODE_READ_SUCCESS,
handler,
);
};
HoneywellBarcodeReader.onBarcodeReadFail = handler => {
subscriptionBarcodeReadFail?.remove();
subscriptionBarcodeReadFail = null;
subscriptionBarcodeReadFail = barcodeReaderEmitter.addListener(
HoneywellBarcodeReader.BARCODE_READ_FAIL,
handler,
);
};
/**
* Stop listening for event
* @param {String} eventName Name of event one of barcodeReadSuccess, barcodeReadFail
* @param {Function} handler Event handler
*/
HoneywellBarcodeReader.offBarcodeReadSuccess = () => {
subscriptionBarcodeReadSuccess?.remove();
};
HoneywellBarcodeReader.offBarcodeReadFail = () => {
subscriptionBarcodeReadFail?.remove();
};
module.exports = HoneywellBarcodeReader;