import React from 'react';
import { ActivityIndicator, Image, View, TouchableOpacity } from 'react-native';
import PropTypes from 'prop-types';
import Camera from 'react-native-camera';
import Permissions from 'react-native-permissions';
import { SafeBlueArea } from '../../BlueComponents';
export default class CameraExample extends React.Component {
static navigationOptions = {
header: null,
};
state = {
isLoading: false,
hasCameraPermission: null,
};
onBarCodeScanned(ret) {
if (this.state.isLoading) return;
this.setState({ isLoading: true }, () => {
const onBarScanned = this.props.navigation.getParam('onBarScanned');
this.props.navigation.goBack();
onBarScanned(ret.data);
});
} // end
componentDidMount() {
Permissions.request('camera').then(response => {
// Response is one of: 'authorized', 'denied', 'restricted', or 'undetermined'
this.setState({ hasCameraPermission: response === 'authorized' });
});
}
render() {
if (this.state.isLoading) {
return (
);
}
const { hasCameraPermission } = this.state;
if (hasCameraPermission === null) {
return ;
} else if (hasCameraPermission === false) {
return ;
} else {
return (
this.onBarCodeScanned(ret)}>
this.props.navigation.goBack(null)}
>
);
}
}
}
CameraExample.propTypes = {
navigation: PropTypes.shape({
goBack: PropTypes.func,
dismiss: PropTypes.func,
getParam: PropTypes.func,
}),
};