moaazsidat / react-native-qrcode-scanner

A QR code scanner component for React Native.
MIT License
2.04k stars 517 forks source link

Keeps repeating scanning same qr code multiple times #406

Open ZAT90 opened 1 year ago

ZAT90 commented 1 year ago

When scanning a QR code, it keeps on repeating the scan process. As a result, it keeps giving the same result multiple times as well and keep on vibrating.

What's happening?

When scanning a QR code, if the camera is kept pointed at the qr code, it keeps on scanning for multiple times

How can it be reproduced?

Keep the camera pointed at a specific QR code and do not move the phone

Build details?

1.4.1

ZAT90 commented 1 year ago

have tried with latest version 1.5.5, still the same. Any idea @moaazsidat ?

BraveEvidence commented 1 year ago

This will help you https://www.youtube.com/watch?v=sE0MEyFA7E4&list=PLQhQEGkwKZUrempLnmxjt7ZCZJu1W3p2i&index=10

Yukesh2412 commented 1 year ago

When scanning a QR code, it keeps on repeating the scan process. As a result, it keeps giving the same result multiple times as well and keep on vibrating.

What's happening?

When scanning a QR code, if the camera is kept pointed at the qr code, it keeps on scanning for multiple times

How can it be reproduced?

Keep the camera pointed at a specific QR code and do not move the phone

Build details?

1.4.1

Hi, I have a possible solution for this issue. You can use a debounce function to limit the number of calls to the onBarCodeRead method and Please let me know if it solves your problem. Here is the code:


// Import debounce from lodash
import debounce from 'lodash.debounce';

// Define your onBarCodeRead function
const onBarCodeRead = (event) => {
  // Do something with the event object
  console.log(event.type, event.data);
};

// Define a debounced version of your onBarCodeRead function using React.useCallback hook
const debouncedOnBarCodeRead = React.useCallback(debounce(onBarCodeRead, 1000), []);

// Pass the debouncedOnBarCodeRead function as a prop to the QRCodeScanner component
<QRCodeScanner onBarCodeRead={debouncedOnBarCodeRead} />```