/* global alert */ import React from 'react'; import { Text, ActivityIndicator, Button, View, TouchableOpacity } from 'react-native'; import { Camera, Permissions, BarCodeScanner } from 'expo'; import PropTypes from 'prop-types'; let EV = require('../../events'); export default class CameraExample extends React.Component { static navigationOptions = { header: null, }; state = { isLoading: false, hasCameraPermission: null, type: Camera.Constants.Type.back, }; async onBarCodeScanned(ret) { if (this.ignoreRead) return; this.ignoreRead = true; setTimeout(() => { this.ignoreRead = false; }, 2000); this.props.navigation.goBack(); EV(EV.enum.CREATE_TRANSACTION_NEW_DESTINATION_ADDRESS, ret.data); } // end async componentWillMount() { const { status } = await Permissions.askAsync(Permissions.CAMERA); this.setState({ hasCameraPermission: status === 'granted', onCameraReady: function() { alert('onCameraReady'); }, barCodeTypes: [BarCodeScanner.Constants.BarCodeType.qr], }); } render() { if (this.state.isLoading) { return ( ); } const { hasCameraPermission } = this.state; if (hasCameraPermission === null) { return ; } else if (hasCameraPermission === false) { return No access to camera; } else { return ( this.onBarCodeScanned(ret)}> { this.setState({ type: this.state.type === Camera.Constants.Type.back ? Camera.Constants.Type.front : Camera.Constants.Type.back, }); }} >