react-native-barcode-scanner-universal
react-native-barcode-scanner-universal copied to clipboard
Close on BarCodeRead
Hi,
Im trying to open an alert when I scan a code, but the scanner keeps running, making various alerts
heres what I have..
<View style={{backgroundColor:'white',flex:1, justifyContent: 'center'}}>
<View style={{width: window.width, height: window.height, alignItems: 'center'}}>
<BarcodeScanner
onBarCodeRead={(code) asd(code}
style={styles.camera}>
{scanArea}
</BarcodeScanner>
</View>
</View>
function asd(c) {
console.log('asdsadsa');
if (Platform.OS === 'ios') {
AlertIOS.alert(
'Scan Complete',
c.data,
);
}
}
any fix? thanks
Create a variable which indicates if a Barcode has already been recognized. If so, do nothing otherwise call the Alert function.
something like this
constructor(props) {
super(props)
this.state = {
qrcode: ''
}
}
onBarCodeRead={(code) => {
if (code.data != this.state.qrcode) {
this.setState({qrcode: code.data})
Alert(code)
}
}}