@scrumble-nl/react-native-honeywell-scanner 1.0.97 → 1.1.0

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.
Files changed (2) hide show
  1. package/README.md +56 -22
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -1,36 +1,70 @@
1
- # react-native-honeywell-scanner-v2
1
+ # React Native Honeywell Scanner
2
2
 
3
- This module is fork of react-native-honeywell-scanner.
3
+ This module is forked and upgraded from react-native-honeywell-scanner-v2.
4
4
 
5
5
  ## Getting started
6
6
 
7
- `$ npm install react-native-honeywell-scanner-v2 --save`
7
+ `$ npm install @scrumble-nl/react-native-honeywell-scanner --save`
8
8
 
9
9
  ## Usage
10
- ```javascript
11
- import HoneywellScanner from 'react-native-honeywell-scanner-v2';
10
+ ```typescript jsx
11
+ import HoneywellScanner from '@scrumble-nl/react-native-honeywell-scanner';
12
12
 
13
13
  ...
14
14
 
15
15
  useEffect(() => {
16
- if( HoneywellScanner.isCompatible ) {
17
- HoneywellScanner.startReader().then((claimed) => {
18
- console.log(claimed ? 'Barcode reader is claimed' : 'Barcode reader is busy');
19
- HoneywellScanner.onBarcodeReadSuccess(event => {
20
- console.log('Received data', event.data);
21
- });
16
+ if (HoneywellScanner.isCompatible) {
17
+ HoneywellScanner.startReader().then(() => {
18
+ HoneywellScanner.onBarcodeReadSuccess((event: {data: string}) => {
19
+ console.log('Received data', event.data);
20
+ });
21
+ });
22
22
 
23
+ return () => {
24
+ HoneywellScanner.stopReader().then(() => {
25
+ HoneywellScanner.offBarcodeReadSuccess();
23
26
  });
27
+ }
28
+ }
29
+ }, []);
30
+ ```
24
31
 
32
+ ### Example code in custom scanner hook
33
+ ```typescript jsx
34
+ import {useEffect, useRef} from 'react';
25
35
 
26
- return(
27
- () => {
28
- HoneywellScanner.stopReader().then(() => {
29
- console.log("Freedom!!");
30
- HoneywellScanner.offBarcodeReadSuccess();
31
- });
32
- }
33
- )
34
- }
35
- }, []);
36
- ```
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;
42
+ };
43
+
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
+ };
69
+ };
70
+ ```
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@scrumble-nl/react-native-honeywell-scanner",
3
- "title": "React Native Honeywell Scanner-v2",
4
- "version": "1.0.97",
3
+ "title": "React Native Honeywell Scanner",
4
+ "version": "1.1.0",
5
5
  "description": "Bridge to use the Honeywell scanner",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -9,7 +9,7 @@
9
9
  "test": "echo \"Error: no test specified\" && exit 1",
10
10
  "build": "tsc"
11
11
  },
12
- "repository": "https://gitlab.com/Scrumble/lekkerland/react-native-honeywell-scanner",
12
+ "repository": "https://gitlab.com/Scrumble/Packages/react-native-honeywell-scanner",
13
13
  "keywords": [
14
14
  "react-native",
15
15
  "honeywell"
@@ -19,9 +19,9 @@
19
19
  "AMI3GO Ltd <enquiry@ami3go.com> (https://ami3go.com)"
20
20
  ],
21
21
  "bugs": {
22
- "url": "https://gitlab.com/Scrumble/lekkerland/react-native-honeywell-scanner/issues"
22
+ "url": "https://gitlab.com/Scrumble/packages/react-native-honeywell-scanner/issues"
23
23
  },
24
- "homepage": "https://gitlab.com/Scrumble/lekkerland/react-native-honeywell-scanner#readme",
24
+ "homepage": "https://gitlab.com/Scrumble/packages/react-native-honeywell-scanner#readme",
25
25
  "license": "MIT",
26
26
  "licenseFilename": "LICENSE",
27
27
  "readmeFilename": "README.md",