react-native-barcodescanner在第一次读取代码后停止读取代码

时间:2016-11-14 01:53:05

标签: react-native barcode-scanner

默认情况下,react-native-barcodescanner会连续读取条形码。我想要阅读条形码然后停下来。我该怎么做?

ZXing可以选择How to stop continuous scanning by zxing-android-embedded in Android,但react-native-barcodescanner似乎没有公开此功能。

2 个答案:

答案 0 :(得分:0)

使用某种旗帜。

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

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

另请查看此示例https://github.com/ideacreation/react-native-barcodescanner/blob/master/Examples/BarcodeScanner/index.android.js

答案 1 :(得分:0)

你可以这样停下来。此代码来自here。转到链接查看完整示例。

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