You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
2.7 KiB

7 years ago
let BlueApp = require('../../BlueApp');
7 years ago
import React from 'react';
7 years ago
import {
Text,
ActivityIndicator,
Button,
View,
TouchableOpacity,
} from 'react-native';
7 years ago
import { Camera, Permissions } from 'expo';
7 years ago
import { AppStorage, LegacyWallet } from '../../class';
7 years ago
import Ionicons from 'react-native-vector-icons/Ionicons';
7 years ago
let EV = require('../../events');
7 years ago
export default class CameraExample extends React.Component {
state = {
7 years ago
isLoading: false,
7 years ago
hasCameraPermission: null,
type: Camera.Constants.Type.back,
};
7 years ago
async onBarCodeRead(ret) {
7 years ago
if (this.ignoreRead) return;
this.ignoreRead = true;
7 years ago
let that = this;
setTimeout(() => {
7 years ago
that.ignoreRead = false;
7 years ago
}, 2000);
7 years ago
7 years ago
this.props.navigation.goBack();
EV(EV.enum.CREATE_TRANSACTION_NEW_DESTINATION_ADDRESS, ret.data);
7 years ago
} // end
async componentWillMount() {
const { status } = await Permissions.askAsync(Permissions.CAMERA);
this.setState({
hasCameraPermission: status === 'granted',
7 years ago
onCameraReady: function() {
7 years ago
alert('onCameraReady');
},
barCodeTypes: [Camera.Constants.BarCodeType.qr],
});
}
render() {
if (this.state.isLoading) {
return (
7 years ago
<View style={{ flex: 1, paddingTop: 20 }}>
7 years ago
<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 }}>
7 years ago
<Camera
style={{ flex: 1 }}
type={this.state.type}
onBarCodeRead={this.onBarCodeRead.bind(this)}
>
7 years ago
<View
style={{
flex: 1,
backgroundColor: 'transparent',
flexDirection: 'row',
7 years ago
}}
>
7 years ago
<TouchableOpacity
style={{
flex: 0.2,
alignSelf: 'flex-end',
alignItems: 'center',
}}
onPress={() => {
this.setState({
7 years ago
type:
this.state.type === Camera.Constants.Type.back
? Camera.Constants.Type.front
: Camera.Constants.Type.back,
7 years ago
});
7 years ago
}}
>
7 years ago
<Button
style={{ fontSize: 18, marginBottom: 10 }}
7 years ago
title="Go back"
onPress={() => this.props.navigation.goBack()}
7 years ago
/>
</TouchableOpacity>
</View>
</Camera>
</View>
);
}
}
7 years ago
}