【发布时间】:2018-09-27 03:59:30
【问题描述】:
我正在使用 react-native-camera 模块来扫描二维码。但是在扫描后它总是打开浏览器并尝试访问 qr 值作为 url。如何停止这个浏览器打开的东西。我只需要获得 qr 值.. 任何帮助。这是我的代码。
_handleBarCodeRead(e) {
try {
Vibration.vibrate();
this.setState({scanning: false});
this.setState({qrcode:e.data});
//Linking.openURL(e.data).catch(err => console.error(‘An error occured’, err));
console.log(e.data);
const {navigate} = this.props.navigation;
navigate(‘TransactionVerified’);
//return;
} catch (error) {
console.log(error);
}
}
getInitialState() {
return {
scanning: true,
cameraType: Camera.constants.Type.back
}
}
render(){
if(this.state.scanning) {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Scan Code
</Text>
<View style={styles.rectangleContainer}>
<Camera
style={styles.camera}
type={this.state.cameraType}
onBarCodeRead={this._handleBarCodeRead.bind(this)}
barCodeTypes={[Camera.constants.BarCodeType.qr]}
>
<View style={styles.rectangleContainer}>
<View style={styles.rectangle}/>
</View>
</Camera>
</View>
{/* <Text style={styles.instructions}>
Double tap R on your keyboard to reload,{‘\n’}
</Text> */}
</View>
);
}
else{
return (<View style={styles.container}>
<Text style={styles.welcome}>
Scan Code
</Text>
{/* <Text style={styles.instructions}>
Double tap R on your keyboard to reload,{‘\n’}
</Text> */}
</View>);
}
}
【问题讨论】:
标签: react-native qr-code react-native-camera