@scrumble-nl/react-native-honeywell-scanner 1.3.0 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,67 +4,23 @@ This module is forked and upgraded from react-native-honeywell-scanner-v2.
4
4
 
5
5
  ## Getting started
6
6
 
7
- `$ npm install @scrumble-nl/react-native-honeywell-scanner --save`
7
+ ```shell
8
+ $ npm install @scrumble-nl/react-native-honeywell-scanner
9
+ ```
8
10
 
9
11
  ## Usage
10
12
  ```typescript jsx
11
- import HoneywellScanner from '@scrumble-nl/react-native-honeywell-scanner';
13
+ import Honeywell from '@scrumble-nl/react-native-honeywell-scanner';
12
14
 
13
15
  ...
14
16
 
15
- useEffect(() => {
16
- if (HoneywellScanner.isCompatible) {
17
- HoneywellScanner.startReader().then(() => {
18
- HoneywellScanner.onBarcodeReadSuccess((event: {data: string}) => {
19
- console.log('Received data', event.data);
20
- });
21
- });
22
-
23
- return () => {
24
- HoneywellScanner.stopReader().then(() => {
25
- HoneywellScanner.offBarcodeReadSuccess();
26
- });
27
- }
28
- }
29
- }, []);
30
- ```
31
-
32
- ### Example code in custom scanner hook
33
- ```typescript jsx
34
- import {useEffect, useRef} from 'react';
35
-
36
- import HoneywellScanner from '@scrumble-nl/react-native-honeywell-scanner';
37
-
38
- type ScanCallback = (scanValue: string) => void;
39
- type Scanner = {
40
- startScanner: () => void;
41
- stopScanner: () => void;
17
+ const startScanner = (callback: (scanValue: string) => void): void => {
18
+ Honeywell.registerListener((event: {data: string}) => {
19
+ callback(event.data.trim());
20
+ });
42
21
  };
43
22
 
44
- export const useScanner = (onScan: ScanCallback): Scanner => {
45
- const callbackRef = useRef<ScanCallback>(onScan);
46
-
47
- useEffect(() => {
48
- callbackRef.current = onScan;
49
- }, [onScan]);
50
-
51
- const startScanner = (): void => {
52
- setTimeout(() => {
53
- HoneywellScanner.startReader().then(() => {
54
- HoneywellScanner.onBarcodeReadSuccess((event: {data: string}) => {
55
- callbackRef.current(event.data.trim());
56
- });
57
- });
58
- }, 100);
59
- };
60
-
61
- const stopScanner = (): void => {
62
- HoneywellScanner.stopReader().then(HoneywellScanner.offBarcodeReadSuccess);
63
- };
64
-
65
- return {
66
- stopScanner,
67
- startScanner,
68
- };
23
+ const stopScanner = (): void => {
24
+ Honeywell.clearEventListeners();
69
25
  };
70
26
  ```
package/dist/index.d.ts CHANGED
@@ -1,2 +1,20 @@
1
- declare const HoneywellScanner: any;
2
- export default HoneywellScanner;
1
+ /**
2
+ * Listen for available events
3
+ * @param {String} eventName Name of event one of barcodeReadSuccess, barcodeReadFail
4
+ * @param {Function} handler Event handler
5
+ */
6
+ interface Scanner {
7
+ registerListener: (event: (...args: any[]) => any) => void;
8
+ clearEventListeners: () => void;
9
+ onBarcodeReadFail?: (event: (...args: any[]) => any) => void;
10
+ }
11
+ declare class Honeywell implements Scanner {
12
+ barcodeReaderEmitter: any;
13
+ subscriptionBarcodeReadSuccess: any;
14
+ subscriptionBarcodeReadFail: any;
15
+ registerListener: (event: (...args: any[]) => any) => void;
16
+ clearEventListeners: () => void;
17
+ onBarcodeReadFail: (event: (...args: any[]) => any) => void;
18
+ }
19
+ declare const _default: Honeywell;
20
+ export default _default;
package/dist/index.js CHANGED
@@ -2,33 +2,33 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const react_native_1 = require("react-native");
4
4
  const { HoneywellScanner } = react_native_1.NativeModules;
5
- /**
6
- * Listen for available events
7
- * @param {String} eventName Name of event one of barcodeReadSuccess, barcodeReadFail
8
- * @param {Function} handler Event handler
9
- */
10
- const barcodeReaderEmitter = new react_native_1.NativeEventEmitter(HoneywellScanner);
11
- var subscriptionBarcodeReadSuccess = null;
12
- var subscriptionBarcodeReadFail = null;
13
- HoneywellScanner.onBarcodeReadSuccess = (handler) => {
14
- subscriptionBarcodeReadSuccess === null || subscriptionBarcodeReadSuccess === void 0 ? void 0 : subscriptionBarcodeReadSuccess.remove();
15
- subscriptionBarcodeReadSuccess = null;
16
- subscriptionBarcodeReadSuccess = barcodeReaderEmitter.addListener(HoneywellScanner.BARCODE_READ_SUCCESS, handler);
17
- };
18
- HoneywellScanner.onBarcodeReadFail = (handler) => {
19
- subscriptionBarcodeReadFail === null || subscriptionBarcodeReadFail === void 0 ? void 0 : subscriptionBarcodeReadFail.remove();
20
- subscriptionBarcodeReadFail = null;
21
- subscriptionBarcodeReadFail = barcodeReaderEmitter.addListener(HoneywellScanner.BARCODE_READ_FAIL, handler);
22
- };
23
- /**
24
- * Stop listening for event
25
- * @param {String} eventName Name of event one of barcodeReadSuccess, barcodeReadFail
26
- * @param {Function} handler Event handler
27
- */
28
- HoneywellScanner.offBarcodeReadSuccess = () => {
29
- subscriptionBarcodeReadSuccess === null || subscriptionBarcodeReadSuccess === void 0 ? void 0 : subscriptionBarcodeReadSuccess.remove();
30
- };
31
- HoneywellScanner.offBarcodeReadFail = () => {
32
- subscriptionBarcodeReadFail === null || subscriptionBarcodeReadFail === void 0 ? void 0 : subscriptionBarcodeReadFail.remove();
33
- };
34
- exports.default = HoneywellScanner;
5
+ class Honeywell {
6
+ constructor() {
7
+ this.barcodeReaderEmitter = new react_native_1.NativeEventEmitter(HoneywellScanner);
8
+ this.subscriptionBarcodeReadSuccess = null;
9
+ this.subscriptionBarcodeReadFail = null;
10
+ this.registerListener = (event) => {
11
+ setTimeout(() => {
12
+ HoneywellScanner.startScanner().then(() => {
13
+ var _a;
14
+ (_a = this.subscriptionBarcodeReadSuccess) === null || _a === void 0 ? void 0 : _a.remove();
15
+ this.subscriptionBarcodeReadSuccess = null;
16
+ this.subscriptionBarcodeReadSuccess = this.barcodeReaderEmitter.addListener(HoneywellScanner.BARCODE_READ_SUCCESS, event);
17
+ });
18
+ }, 100);
19
+ };
20
+ this.clearEventListeners = () => {
21
+ HoneywellScanner.stopReader().then(() => {
22
+ var _a;
23
+ (_a = this.subscriptionBarcodeReadSuccess) === null || _a === void 0 ? void 0 : _a.remove();
24
+ });
25
+ };
26
+ this.onBarcodeReadFail = (event) => {
27
+ var _a;
28
+ (_a = this.subscriptionBarcodeReadFail) === null || _a === void 0 ? void 0 : _a.remove();
29
+ this.subscriptionBarcodeReadFail = null;
30
+ this.subscriptionBarcodeReadFail = this.barcodeReaderEmitter.addListener(HoneywellScanner.BARCODE_READ_FAIL, event);
31
+ };
32
+ }
33
+ }
34
+ exports.default = new Honeywell();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@scrumble-nl/react-native-honeywell-scanner",
3
3
  "title": "React Native Honeywell Scanner",
4
- "version": "1.3.0",
4
+ "version": "1.3.2",
5
5
  "description": "Bridge to use the Honeywell scanner",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -25,12 +25,8 @@
25
25
  "license": "MIT",
26
26
  "licenseFilename": "LICENSE",
27
27
  "readmeFilename": "README.md",
28
- "peerDependencies": {
29
- "react": "16.*",
30
- "react-native": "0.*"
31
- },
32
- "devDependencies": {
33
- "react": "16.*",
34
- "react-native": "0.*"
28
+ "dependencies": {
29
+ "react": "^17.0.2",
30
+ "react-native": "^0.68.5"
35
31
  }
36
32
  }