forked from Hyper-Matrix/SPECTRUM-APP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scanner.js
206 lines (186 loc) · 6.84 KB
/
Scanner.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import React from 'react';
import { StyleSheet, Text, View,Dimensions,ImageBackground, Alert,ScrollView,Picker} from 'react-native';
import { createStackNavigator, createAppContainer} from "react-navigation";
import * as Permissions from 'expo-permissions';
import { BarCodeScanner } from 'expo-barcode-scanner';
import * as firebase from 'firebase'
import {firebaseConfig} from './config'
import { TextInput,Button } from 'react-native-paper';
const WIDTH = Dimensions.get('screen').width
const HEIGHT = Dimensions.get('screen').height
firebase.initializeApp(firebaseConfig);
class Decode extends React.Component{
state={
name:" ",
regd:" ",
component:" ",
purpose:" ",
mylist:[]
}
componentDidMount(){
const item = firebase.database().ref("users");
item.on("value",datasnap=>{
console.log(datasnap.val())
})
}
saveitem(){
console.log(this.state)
const name = firebase.database().ref("users");
const data = this.props.navigation.getParam("data", "NO-QR");
name.push().set({
name:this.state.name,
regd:this.state.regd,
priority:data,
component:this.state.component,
purpose:this.state.purpose,
time:Date.now()
})
this.setState({name:" "})
this.setState({regd:" "})
this.setState({component:" "})
this.setState({purpose:" "})
}
render(){
const data = this.props.navigation.getParam("data", "NO-QR");
return (<ImageBackground
source={require('./media/homeback.jpg')}
style={styles.image}
>
< ScrollView >
<View style={{flex:1,backgroundColor:'transparent',alignItems:'center',justifyContent:'center'}}>
<Text style={{color:'white',fontSize:30,alignSelf:'center',fontWeight:'bold',textShadowColor:'black',textShadowOffset: {width: -1, height: 1},
textShadowRadius: 15,letterSpacing:3}}>ISSUE COMPONENTS</Text>
<TextInput theme={{colors:{text:"white",primary:"white",placeholder:"white"}}} style={styles.Textinput1} mode="outlined" placeholder="Enter Name" label="Name"
value={this.state.name} onChangeText={(text)=>this.setState({name:text})}/>
<TextInput theme={{colors:{text:"white",primary:"white",placeholder:"white"}}} style={styles.Textinput1} mode="outlined" placeholder="Enter Registration Number" label="Regd.no"value={this.state.regd} onChangeText={(text)=>this.setState({regd:text})}/>
<TextInput theme={{colors:{text:"white",primary:"white",placeholder:"white"}}} style={styles.Textinput1} mode="outlined" disabled='true'>{data}</TextInput>
<View
style={{marginTop:22,
borderColor: 'white',
borderWidth:1,
borderRadius: 3,
}}>
<Picker style={{ backgroundColor: 'rgba(0,0,0,0.6)',
width:350,
color:"white",borderColor:"white",borderWidth:5}} selectedValue={this.state.component} mode="dropdown" onValueChange={(text)=>this.setState({component:text})}>
<Picker.Item label = "Select Required Component"/>
<Picker.Item label = "Arduino" value = "Arduino" />
<Picker.Item label = "Raspberry" value = "Raspberry" />
<Picker.Item label = "Motor Driver" value = "motordriver" />
</Picker>
</View>
<TextInput theme={{colors:{text:"white",primary:"white",placeholder:"white"}}} style={styles.Textinput1} mode="outlined" placeholder="Enter Purpose" label="Purpose" value={this.state.purpose} onChangeText={(text)=>this.setState({purpose:text})}/>
<Button mode="contained"
onPress={()=>this.saveitem() }
color="#00BCD4"
labelStyle={{color:"white",letterSpacing:3}}
style ={{margin:5, height:50,padding:8,width:360,borderRadius:30,opacity:0.7,borderColor
:"black",borderWidth:3,padding:5,marginTop:22} }>
SUBMIT
</Button>
</View>
</ ScrollView>
</ImageBackground>
);
}
}
class Scanner extends React.Component {
state = {
hasCameraPermission: null, // if app has permissions to acess camera
isScanned: false // scanned-set to false, tertiary operator works below, remember initial condition is false
}
async componentDidMount() {
// ask for camera permission
const { status } = await Permissions.askAsync(Permissions.CAMERA);
console.log(status);
this.setState({ hasCameraPermission: status === "granted" ? true : false });
}
handleBarCodeScanned = ({ type, data }) => {
// Do something here
this.props.navigation.navigate('Decode', {
data: data
});
}
render() {
const { hasCameraPermission, isScanned } = this.state;
if(hasCameraPermission === null){
console.log("Requesting permission");
return (<ImageBackground
source={require('./media/homeback.jpg')}
style={styles.image}
>
<Text style={{color:'white',fontSize:30,marginTop:10,alignSelf:'center',fontWeight:'bold',textShadowColor:'black',textShadowOffset: {width: -1, height: 1},
textShadowRadius: 15,letterSpacing:2}}>REQUESTING PERMISSION</Text>
</ImageBackground>
);
}
if(hasCameraPermission === false){
return (
Alert.alert("Please grant Camera permission")
)
}
if(hasCameraPermission === true && !isScanned && this.props.navigation.isFocused() ){
return <ImageBackground
source={require('./media/homeback.jpg')}
style={styles.image}
>
<View style = {{
flex: 1,
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
backgroundColor:'transparent'
}}>
<Text style={{color:'white',fontSize:30,marginTop:10,alignSelf:'center',fontWeight:'bold',textShadowColor:'black',textShadowOffset: {width: -1, height: 1},
textShadowRadius: 15,letterSpacing:2}}>Scan code inside window</Text>
<View style={{borderColor:'white',
borderRadius:10,
borderWidth:5,
backgroundColor:'rgba(0,0,0,0.6)'}}>
<BarCodeScanner
onBarCodeScanned = { isScanned ? undefined : this.handleBarCodeScanned }
style = {{
height: 600,
width: 350
}}
>
</BarCodeScanner>
</View>
</View>
</ImageBackground>
}
else{
return (
<Text>LOADING</Text>
);
}
}
}
const Appnav = createStackNavigator(
{
Scanner:Scanner,
Decode:Decode
},{
headerMode:'none'
}
)
export default createAppContainer(Appnav);
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#303F9F',
},
image:{
flex:1,
resizeMode: "cover",
},
cardimage:{
resizeMode:'cover',
},
Textinput1:{
backgroundColor: 'rgba(0,0,0,0.6)',
width:350,
marginTop:20,
color:"white",
}
})