This React Native module enables seamless integration with Zebra RFID readers and barcode scanners.
npm install react-native-zebra-rfid-barcode-ef-techThis React Native module enables seamless integration with Zebra RFID readers and barcode scanners.
https://github.com/efernandes-tech/react-native-zebra-rfid-barcode-ef-tech/assets/78204178/a54c4616-76ce-48da-86cb-6ceaab1beeef
``sh`
npm install react-native-zebra-rfid-barcode-ef-tech
yarn add react-native-zebra-rfid-barcode-ef-tech
`sh`
yarn android
`js
import {
ZebraEvent,
ZebraEventEmitter,
getAllDevices,
connectToDevice,
type ZebraResultPayload,
type ZebraRfidResultPayload,
} from 'react-native-zebra-rfid-barcode-ef-tech';
// ...
`
`js`
const listDevices = await getAllDevices();
// will return array of devices names like ["RFD+19189414", "RFD+018134912"]
`jsx
useEffect(() => {
const deviceConnectEvent = ZebraEventEmitter.addListener(
ZebraEvent.ON_DEVICE_CONNECTED,
(e: ZebraResultPayload) => {
console.log(e.data); // "Connect successfully" || "Connect failed"
}
);
return () => {
deviceConnectEvent.remove();
};
}, []);
//...
`
`js
useEffect(() => {
const barcodeEvent = ZebraEventEmitter.addListener(
ZebraEvent.ON_BARCODE,
(e: ZebraResultPayload) => {
handleBarcodeEvent(e.data); // string
}
);
return () => {
barcodeEvent.remove();
};
}, []);
const handleBarcodeEvent = useCallback(
debounce((newData: string) => {
setListBarcodes((pre) => [...pre, newData]);
}, 200),
[]
);
`
`js
useEffect(() => {
const rfidEvent = ZebraEventEmitter.addListener(
ZebraEvent.ON_RFID,
(e: ZebraRfidResultPayload) => {
handleRfidEvent(e.data); // array of string tags
}
);
return () => {
rfidEvent.remove();
};
}, []);
const handleRfidEvent = useCallback(
debounce((newData: string[]) => {
setListRfid((pre) => [...pre, ...newData]);
}, 200),
[]
);
`
`jsx
import React, { useCallback, useEffect, useState } from 'react';
import debounce from 'lodash/debounce';
import {
FlatList,
StyleSheet,
Text,
TouchableOpacity,
View,
} from 'react-native';
import {
ZebraEvent,
ZebraEventEmitter,
connectToDevice,
getAllDevices,
type ZebraResultPayload,
type ZebraRfidResultPayload,
} from 'react-native-zebra-rfid-barcode-ef-tech';
export default function App() {
const [listDevices, setListDevices] = useState
const [listBarcodes, setListBarcodes] = useState
const [listRfid, setListRfid] = useState
useEffect(() => {
getListRfidDevices();
const barcodeEvent = ZebraEventEmitter.addListener(
ZebraEvent.ON_BARCODE,
(e: ZebraResultPayload) => {
handleBarcodeEvent(e.data);
}
);
const rfidEvent = ZebraEventEmitter.addListener(
ZebraEvent.ON_RFID,
(e: ZebraRfidResultPayload) => {
handleRfidEvent(e.data);
}
);
const deviceConnectEvent = ZebraEventEmitter.addListener(
ZebraEvent.ON_DEVICE_CONNECTED,
(e: ZebraResultPayload) => {
console.log(e.data); // "Connect successfully" || "Connect failed"
}
);
return () => {
barcodeEvent.remove();
rfidEvent.remove();
deviceConnectEvent.remove();
};
}, []);
const handleRfidEvent = useCallback(
debounce((newData: string[]) => {
setListRfid((pre) => [...pre, ...newData]);
}, 200),
[]
);
const handleBarcodeEvent = useCallback(
debounce((newData: string) => {
setListBarcodes((pre) => [...pre, newData]);
}, 200),
[]
);
const getListRfidDevices = async () => {
const listDevices = await getAllDevices();
setListDevices(listDevices);
};
return (
maxHeight: 200,
}}
>
Devices: {listDevices.length}
ItemSeparatorComponent={() =>
data={listDevices}
renderItem={({ item }) => (
style={styles.item}
>
)}
/>
Barcodes: {listBarcodes.length}
ItemSeparatorComponent={() =>
data={listBarcodes}
renderItem={({ item }) => (
)}
/>
RFIDs: {listRfid.length}
ItemSeparatorComponent={() =>
data={listRfid}
renderItem={({ item }) => (
)}
/>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
paddingHorizontal: 16,
backgroundColor: 'white',
},
partial: {
flex: 1,
},
item: {
height: 50,
paddingHorizontal: 15,
justifyContent: 'center',
},
separator: {
height: 1,
backgroundColor: '#ccc',
},
text: {
color: '#333',
},
title: {
fontWeight: 'bold',
fontSize: 16,
marginVertical: 5,
},
});
``
MIT
---
Made with create-react-native-library