Skip to content

Commit

Permalink
Fixed hook to return proper function
Browse files Browse the repository at this point in the history
  • Loading branch information
premkumart committed Dec 25, 2020
1 parent 4eb04ad commit 721d5ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-native-scanner-zebra",
"title": "React Native Scanner Zebra",
"version": "0.1.2",
"version": "0.1.3",
"description": "React Native module for Zebra barcode scanners",
"homepage": "https://github.com/crypton-tech/react-native-scanner-zebra#readme",
"baseUrl": "https://github.com/crypton-tech/react-native-scanner-zebra",
Expand Down
22 changes: 10 additions & 12 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,22 @@ const supportedEvents = [
'scanner-disconnected',
]

const setEnabled = (isEnabled: boolean) => {
NativeModules.ZebraScanner.setEnabled(isEnabled)
}

const getActiveScanners = (callback: CallbackScanners) => {
NativeModules.ZebraScanner.getActiveScanners((scanners: Scanner[]) => {
callback(scanners)
})
}

const useZebraScanner = (
onScan: EventBarcodeHandler,
onEvent: EventHandler | undefined
) => {
useLayoutEffect(() => {
const handleEvent = (data: EventBarcode) => {
console.log('Event: Barcode', data)
if (onScan) {
onScan(data.barcode || '', data.id)
}
Expand All @@ -49,7 +58,6 @@ const useZebraScanner = (
supportedEvents.forEach((event: string) => {
listeners.push(
RNZebraScanner.addListener(event, (data) => {
console.log('Event:', event, data)
onEvent(event, data.id || '')
})
)
Expand All @@ -63,16 +71,6 @@ const useZebraScanner = (
}
})

const setEnabled = (isEnabled: boolean) => {
NativeModules.ZebraScanner.setEnabled(isEnabled)
}

const getActiveScanners = (callback: CallbackScanners) => {
NativeModules.ZebraScanner.getActiveScanners((scanners: Scanner[]) => {
callback(scanners)
})
}

return {
setEnabled,
getActiveScanners,
Expand Down

0 comments on commit 721d5ba

Please sign in to comment.