-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqrscanner.js
More file actions
134 lines (121 loc) · 3.54 KB
/
qrscanner.js
File metadata and controls
134 lines (121 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// referenced from https://stackoverflow.com/questions/57264546/how-to-make-a-qr-code-scanner-in-react-native-using-expo
import * as React from 'react';
import {
Text,
View,
StyleSheet,
Button
} from 'react-native';
import Constants from 'expo-constants';
import * as Permissions from 'expo-permissions';
import { WebView } from 'react-native-webview';
import {
BarCodeScanner
} from 'expo-barcode-scanner';
import styles from './styles';
import RESTfunct from './requestsOfficial.js';
export default class QRScanner extends React.Component {
constructor(props) {
super(props);
this.funct = props.funct;
this.state = {
hasCameraPermission: null,
scanned: false,
product: {
name: '',
vendor_email: '',
price: ''
},
qr_id: ''
}
}
async componentDidMount() {
this.getPermissionsAsync();
}
getPermissionsAsync = async() => {
const {
status
} = await Permissions.askAsync(Permissions.CAMERA);
this.setState({
hasCameraPermission: status === 'granted'
});
};
render() {
const {
hasCameraPermission,
scanned
} = this.state;
if (hasCameraPermission === null) {
return <Text > Requesting
for camera permission </Text>;
}
if (hasCameraPermission === false) {
return <Text > No access to camera </Text>;
}
if (!scanned) {
return (
<View style = {styles.scanner}>
<BarCodeScanner onBarCodeScanned = {
scanned ? undefined : this.handleBarCodeScanned
}
style = {
StyleSheet.absoluteFillObject
}/>
<View style={styles.buttonContainer}>
<Button
onPress={() => this.funct.setPage('home')}
title="Go back"
/>
</View>
</View>
);
}
else {
while (this.state.product.price === undefined) {
var waste = 1 + 2;
}
return (
<View style={styles.scanner_alt}>
<View style={styles.scanner_alt_top}>
<Text style={{fontSize: 15, margin: 5}}>{this.state.product.name}</Text>
<Text style={{fontSize: 15, margin: 5}}>{this.state.product.price}</Text>
<Text style={{fontSize: 15, margin: 5}}>{this.state.product.vendor_email}</Text>
</View>
<WebView
source={{ uri: 'https://alexguan8.github.io/arhost/' + this.state.qr_id }}
style={{ height:720 }}
/>
<View style={styles.doubleButtons}>
<View style={styles.buttonContainer}>
<Button title = { 'Scan again' } onPress = {() => {
this.setState({scanned: false});
this.state.product.price = undefined;
}}/>
</View>
<View style={styles.buttonContainer}>
<Button title = { 'Purchase' } onPress = {() => this.funct.setPage('login')}/>
</View>
</View>
</View>
)
}
}
handleBarCodeScanned = ({type, data}) => {
RESTfunct.getProduct.name(data, (name_) => {
this.state.product.name = name_;
this.funct.setProduct('name', name_);
});
RESTfunct.getProduct.vendor_email(data, (vendor_email_) => {
this.state.product.vendor_email = vendor_email_;
this.funct.setProduct('vendor_email', vendor_email_);
});
RESTfunct.getProduct.price(data, (price_) => {
this.state.product.price = price_;
this.funct.setProduct('price', price_);
});
this.setState({
scanned: true,
qr_id: data
});
};
}