Hello, Currently I’m trying to read QR Code and print the result to my console. But the method onBarCodeScanned doesn’t seemed to be called when the camera detects a QR code. Currently I’m using 3 devices (Redmi 5A, iPhone 7, Samsung Galaxy Tab 7) and none works. Here is my dependency:
"dependencies": {
"expo": "^27.0.1",
"react": "16.3.1",
"react-native": "~0.55.2",
"react-navigation": "^2.8.0"
}
And here is my code
import React from 'react';
import { StyleSheet, Text, View, Picker, ScrollView, Alert } from 'react-native';
import { BarCodeScanner, Permissions } from 'expo';
export default class ScanQR extends React.Component {
static navigationOptions = () => ({
title: 'Scan QR'
})
state = {
hasCameraPermission: null,
}
constructor(props){
super(props);
}
_handleBarCodeRead = ({ type, data }) => {
console.log("Success...");
// alert('Bar code with type ${type} and data ${data} has been scanned!');
}
async componentWillMount() {
const { status } = await Permissions.askAsync(Permissions.CAMERA);
this.setState({hasCameraPermission: status === 'granted'});
}
render() {
console.log("Rendering...");
const { hasCameraPermission } = this.state;
if (hasCameraPermission === null) {
return <View><Text>Requesting for camera permission</Text></View>;
}
if (hasCameraPermission === false) {
return <View><Text>No access to camera</Text></View>;
}
return (
<View style={styles.container}>
<BarCodeScanner
onBarCodeScanned={this._handleBarCodeRead}
style={StyleSheet.absoluteFill}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
paddingLeft: 15,
paddingRight: 15,
paddingTop: 10,
backgroundColor: '#fff'
}
});
If anyone can help, it would be very appreciated. Thanks!