我正在尝试为反应原生的android构建一个QR扫描程序。我有以下代码,但它不扫描任何东西。代码中我需要什么才能使它工作?
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
View,
Text,
TouchableHighlight,
TouchableOpacity,
Image,
Button
} from 'react-native';
import BarcodeScanner from 'react-native-barcodescanner';
export default class test extends React.Component {
constructor(props) {
super(props);
this.state = {
torchMode: 'off',
cameraType: 'back',
};
}
barcodeReceived(e) {
console.log('Barcode: ' + e.data);
console.log('Type: ' + e.type);
}
render() {
return (
<View style={{flex: 1, flexDirection: 'row'}}>
<BarcodeScanner
onBarCodeRead={this.barcodeReceived}
style={{ flex: 1 }}
torchMode={this.state.torchMode}
cameraType={this.state.cameraType}
/>
</View>
);
}
}
AppRegistry.registerComponent('test', () => test);
&#13;
答案 0 :(得分:0)
使用以便您可以对功能进行分类
onBarCodeRead={this.barcodeReceived.bind(this)}
可能这可以帮到你!!