-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
89 lines (77 loc) · 2.02 KB
/
App.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
import * as React from 'react';
import { Text, View, Alert } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import Ionicons from 'react-native-vector-icons/Ionicons';
import QRScanner from './parts/qrscanner';
import PUVlist from './parts/puvlist';
var ws;
//websocket connection
const websocketConnection = () => {
ws = new WebSocket('ws://192.168.1.15:8082');
ws.onclose = (e) => {
connectionError();
}
ws.onerror = (e) => {
console.log(e.message);
}
ws.onopen = () => {
console.log("connected");
}
}
//Calling the websocket connection function
websocketConnection();
//This function will be called on websocket onclose event
const connectionError = () => Alert.alert(
"Connection error",
"A problem occured when connecting you with other dispatcher",
[
{
text: "Refresh",
onPress: () => {
websocketConnection();
}
}
]
);
function scanner() {
return (
<QRScanner
ws = {ws}
/>
);
}
function puvs({navigation}) {
return (
<PUVlist
navigation = {navigation}
ws = {ws}
/>
);
}
const Tab = createBottomTabNavigator();
export default function App() {
return (
<NavigationContainer>
<Tab.Navigator
screenOptions={({ route }) => ({
tabBarIcon: ({ focused, color, size }) => {
let iconName;
if (route.name === 'Scanner') {
iconName = 'qr-code';
} else if (route.name === 'PUVS') {
iconName = 'bus';
}
// You can return any component that you like here!
return <Ionicons name={iconName} size={size} color={color} />;
},
tabBarActiveTintColor: 'green',
tabBarInactiveTintColor: 'gray',
})}
>
<Tab.Screen name="Scanner" component={scanner} />
<Tab.Screen name="PUVS" component={puvs} />
</Tab.Navigator>
</NavigationContainer>
);
}