I took the code from the snack example
here is my code
import React, { Component } from 'react';
import {
Text,
View,
ScrollView,
TextInput,
Button,
TouchableOpacity,
TouchableHighlight,
} from 'react-native';
import { BarCodeScanner, Permissions } from 'expo';
class share extends Component {
static navigationOptions = {
title: 'share',
tabBarLabel: 'share',
}
state = {
hasCameraPermission: null,
}
componentDidMount() {
this._requestCameraPermission();
}
_requestCameraPermission = async () => {
const { status } = await Permissions.askAsync(Permissions.CAMERA);
this.setState({
hasCameraPermission: status === 'granted',
});
};
render() {
const { hasCameraPermission } = this.state;
if (hasCameraPermission === null) {
return <View />;
} else if (hasCameraPermission === false) {
return <Text>No access to camera</Text>;
} else {
return (
<View style={{flex: 1}}>
<BarCodeScanner
onBarCodeRead={this._handleBarCodeRead}
/>
</View>
);
}
}
_handleBarCodeRead = (data) => {
alert(JSON.stringify(data));
}
}
const styles = {
};
export default shop;