I am developing react native app, there is a QR code scanner screen, i want to trigger an alert if the QR code which i try to scan is empty. QR code with data work fine.
i am using version :
“react-native-qrcode-scanner”: “^1.5.3”,
please help me.
I tried to add a logic through onread event to check the data null or empty,it did not work, But when i scanned empty QR code it continuously scanning, does not go through handleBarCodeScanned function.
const handleBarCodeScanned = ({data}: BarCodeReadEvent) => {
console.log('Scanned QR code data1:', data);
if (data !== null && data.trim() !== '') {
const splitted = data.split('|')[0];
dispatch(changeState(['isQRProcessing', true]));
dispatch(scanQR({bookingRef: splitted.trim()}));
} else {
console.log('Empty QR Code or Timeout occurred');
dispatch (
showAlertModal(
getAlertObject(
'Empty QR Code',
'Please scan a valid QR code.',
ALERT_TYPES.FAILED,
'Try Another',
'Close',
() => {
dispatch(changeState(['isQRProcessing', false]));
},
),
)
);
}
};
{!isQRProcessing && (
<QRCodeScanner
onRead={handleBarCodeScanned}
reactivate={true}
reactivateTimeout={2000}
showMarker={true}
checkAndroid6Permissions={true}
markerStyle={ScannerStyles.marker}
cameraStyle={ScannerStyles.camera}
cameraProps={{
autoFocus: 'on',
}}
/>
)}