forked from infuse-us/react-native-clover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (32 loc) · 1.14 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
import { NativeModules, NativeEventEmitter } from 'react-native';
import { useEffect } from 'react';
const { RNCloverBridge } = NativeModules;
export default {
...RNCloverBridge,
authenticate: (force = false, timeout = 10000) =>
RNCloverBridge.authenticate(force, timeout),
getMerchant: () => RNCloverBridge.getMerchant(),
getOrder: (orderId) => RNCloverBridge.getOrder(orderId),
getInventoryItems: () => RNCloverBridge.getInventoryItems(),
isFlex: () => RNCloverBridge.isFlex,
isMini: () => RNCloverBridge.isMini,
getSpaVersion: () => RNCloverBridge.getSpaVersion,
disableCustomerMode: (requirePasscode = false) =>
RNCloverBridge.disableCustomerMode(requirePasscode),
};
export const useScanner = (callback, enabled = true) => {
useEffect(() => {
if (enabled) {
const eventEmitter = new NativeEventEmitter(RNCloverBridge);
const listener = eventEmitter.addListener(
RNCloverBridge.EVENT.BARCODE_SCANNER,
callback,
);
RNCloverBridge.registerScanner();
return () => {
listener.remove();
RNCloverBridge.unregisterScanner();
};
}
}, [enabled, callback]);
};