0

By default react-native-barcodescanner continuously reads bar codes. I'd like it to read a bar code and then stop. How do I do that?

ZXing has the option to do this, How to stop continuous scanning by zxing-android-embedded in Android, but react-native-barcodescanner seems to not expose this functionality.

Community
  • 1
  • 1

2 Answers2

0

Use some kind of flag.

  constructor(props) {
    super(props);
    this.scanSuccess = false;
    ....
  }

  barcodeReceived(e) {
    if (this.scanSuccess) return;
    console.log("bar code detected", JSON.stringify(e));
    this.scanSuccess = true;
    .....
  }

Also check this example https://github.com/ideacreation/react-native-barcodescanner/blob/master/Examples/BarcodeScanner/index.android.js

vinayr
  • 11,026
  • 3
  • 46
  • 42
0

You can stop like this. This code is from here. Go to link to see full example.

  onBarCodeRead: function(e) {
    this.setState({showCamera: false});
    AlertIOS.alert(
        "Barcode Found!",
        "Type: " + e.type + "\nData: " + e.data
    );
  }
Monty
  • 361
  • 1
  • 3
  • 8