【问题标题】:react-native-barcodescanner stop reading codes after first code readreact-native-barcodescanner 在第一次读取代码后停止读取代码
【发布时间】:2016-11-14 01:53:05
【问题描述】:

默认情况下 react-native-barcodescanner 连续读取条形码。我希望它读取条形码然后停止。我该怎么做?

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

【问题讨论】:

    标签: react-native barcode-scanner


    【解决方案1】:

    使用某种标志。

      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

    【讨论】:

    • 这是一个穷人的自旋储物柜,是否可以保证这是线程安全的?
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2014-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多