-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRide.js
119 lines (109 loc) · 3.14 KB
/
Ride.js
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
import React, { Component } from "react";
import { View, Text, StyleSheet, TouchableOpacity } from "react-native";
import * as Permissions from "expo-permissions";
import { BarCodeScanner } from "expo-barcode-scanner";
export default class TransactionScreen extends Component {
constructor(props) {
super(props);
this.state = {
domState: "normal",
hasCameraPermissions: null,
scanned: false,
scannedData: ""
};
}
getCameraPermissions = async domState => {
const { status } = await Permissions.askAsync(Permissions.CAMERA);
//const { status } = Permissions.askAsync(Permissions.CAMERA);
//const { status } = await Permissions.askAsync(Permissions);
//const { status } = await Permissions.askAsync(CAMERA);
this.setState({
/*status === "granted" is true when user has granted permission
status === "granted" is false when user has not granted the permission
*/
hasCameraPermissions: status === "granted",
domState: domState,
scanned: false
});
};
handleBarCodeScanned = async ({ type, data }) => {
this.setState({
scannedData: data,
domState: "normal",
scanned: true
});
};
render() {
const { domState, hasCameraPermissions, scannedData, scanned } = this.state;
if (domState === "scanner") {
return (
<BarCodeScanner
onBarCodeScanned={scanned ? undefined : this.handleBarCodeScanned}
style={StyleSheet.absoluteFillObject}
/>
);
}
return (
<View style={styles.container}>
<Text style={styles.text}>
{hasCameraPermissions ? scannedData : "Request for Camera Permission"}
</Text>
{/*
<TouchableOpacity
style={[styles.button, { marginTop: 25 }]}
onPress= this.getCameraPermissions("scanner")
>
<Text style={styles.buttonText}>Scan QR Code</Text>
</TouchableOpacity>
*/}
{
<TouchableOpacity
style={[styles.button, { marginTop: 25 }]}
onPress={() => this.getCameraPermissions("scanner")}
>
<Text style={styles.buttonText}>Scan QR Code</Text>
</TouchableOpacity>
}
{/*
<TouchableOpacity
style={[styles.button, { marginTop: 25 }]}
onPress={() => this.getCameraPermissions()}
>
<Text style={styles.buttonText}>Scan QR Code</Text>
</TouchableOpacity>
*/}
{/*
<TouchableOpacity
style={[styles.button, { marginTop: 25 }]}
onPress={() => this.getCameraPermissions("scanner")}
/>
*/}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#D0E6F0"
},
text: {
color: "#4C5D70",
fontSize: 15
},
button: {
width: "43%",
height: 55,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#FBE5C0",
borderRadius: 15,
borderWidth: 2
},
buttonText: {
fontSize: 24,
color: "#4C5D70"
}
});