BlueWallet/screen/send/scanQrAddress.js

93 lines
2.6 KiB
JavaScript
Raw Normal View History

2018-03-18 02:48:23 +00:00
/* global alert */
2018-01-30 22:42:38 +00:00
import React from 'react';
2018-07-07 14:04:32 +01:00
import { Text, ActivityIndicator, Button, View, TouchableOpacity } from 'react-native';
2018-09-18 02:48:53 -04:00
import { Camera, Permissions, BarCodeScanner } from 'expo';
2018-03-18 02:48:23 +00:00
import PropTypes from 'prop-types';
2018-03-17 22:39:21 +02:00
let EV = require('../../events');
2018-01-30 22:42:38 +00:00
export default class CameraExample extends React.Component {
2018-05-12 21:27:34 +01:00
static navigationOptions = {
header: null,
2018-05-12 21:27:34 +01:00
};
2018-01-30 22:42:38 +00:00
state = {
2018-03-17 22:39:21 +02:00
isLoading: false,
2018-01-30 22:42:38 +00:00
hasCameraPermission: null,
type: Camera.Constants.Type.back,
};
2018-09-18 02:52:12 -04:00
async onBarCodeScanned(ret) {
2018-03-24 21:24:20 +00:00
if (this.ignoreRead) return;
this.ignoreRead = true;
2018-03-17 22:39:21 +02:00
setTimeout(() => {
2018-03-24 21:24:20 +00:00
this.ignoreRead = false;
}, 2000);
2018-01-30 22:42:38 +00:00
2018-03-17 22:39:21 +02:00
this.props.navigation.goBack();
EV(EV.enum.CREATE_TRANSACTION_NEW_DESTINATION_ADDRESS, ret.data);
2018-01-30 22:42:38 +00:00
} // end
async componentWillMount() {
const { status } = await Permissions.askAsync(Permissions.CAMERA);
this.setState({
hasCameraPermission: status === 'granted',
2018-03-17 22:39:21 +02:00
onCameraReady: function() {
2018-01-30 22:42:38 +00:00
alert('onCameraReady');
},
2018-09-18 02:48:53 -04:00
barCodeTypes: [BarCodeScanner.Constants.BarCodeType.qr],
2018-01-30 22:42:38 +00:00
});
}
render() {
if (this.state.isLoading) {
return (
2018-03-17 22:39:21 +02:00
<View style={{ flex: 1, paddingTop: 20 }}>
2018-01-30 22:42:38 +00:00
<ActivityIndicator />
</View>
);
}
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 }}>
<Camera style={{ flex: 1 }} type={this.state.type} onBarCodeRead={ret => this.onBarCodeScanned(ret)}>
2018-01-30 22:42:38 +00:00
<View
style={{
flex: 1,
backgroundColor: 'transparent',
flexDirection: 'row',
2018-03-17 22:39:21 +02:00
}}
>
2018-01-30 22:42:38 +00:00
<TouchableOpacity
style={{
flex: 0.2,
alignSelf: 'flex-end',
alignItems: 'center',
}}
onPress={() => {
this.setState({
type: this.state.type === Camera.Constants.Type.back ? Camera.Constants.Type.front : Camera.Constants.Type.back,
2018-01-30 22:42:38 +00:00
});
2018-03-17 22:39:21 +02:00
}}
>
<Button style={{ fontSize: 18, marginBottom: 10 }} title="Go back" onPress={() => this.props.navigation.goBack()} />
2018-01-30 22:42:38 +00:00
</TouchableOpacity>
</View>
</Camera>
</View>
);
}
}
2018-03-17 22:39:21 +02:00
}
2018-03-18 02:48:23 +00:00
CameraExample.propTypes = {
navigation: PropTypes.shape({
goBack: PropTypes.function,
}),
};