BlueWallet/screen/send/scanQrAddress.js

118 lines
3 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-03-17 22:39:21 +02:00
import {
Text,
ActivityIndicator,
Button,
View,
TouchableOpacity,
} from 'react-native';
2018-01-30 22:42:38 +00:00
import { Camera, Permissions } from 'expo';
2018-05-12 21:27:34 +01:00
import Ionicons from 'react-native-vector-icons/Ionicons';
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 = {
tabBarLabel: 'Send',
tabBarIcon: ({ tintColor, focused }) => (
<Ionicons
name={focused ? 'md-paper-plane' : 'md-paper-plane'}
size={26}
style={{ color: tintColor }}
/>
),
};
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-03-17 22:39:21 +02:00
async onBarCodeRead(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');
},
barCodeTypes: [Camera.Constants.BarCodeType.qr],
});
}
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 }}>
2018-03-17 22:39:21 +02:00
<Camera
style={{ flex: 1 }}
type={this.state.type}
2018-03-18 02:52:01 +00:00
onBarCodeRead={ret => this.onBarCodeRead(ret)}
2018-03-17 22:39:21 +02:00
>
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({
2018-03-17 22:39:21 +02:00
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
}}
>
2018-01-30 22:42:38 +00:00
<Button
style={{ fontSize: 18, marginBottom: 10 }}
2018-03-17 22:39:21 +02:00
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,
}),
};