BlueWallet/screen/send/scanQrAddress.js

106 lines
2.7 KiB
JavaScript
Raw Normal View History

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