-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
165 lines (147 loc) · 4.79 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
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
import React, { useState } from "react";
// Navigation
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
const Tab = createBottomTabNavigator();
const Stack = createNativeStackNavigator();
// Icons
import { Ionicons } from '@expo/vector-icons';
// Amplify
import Amplify from 'aws-amplify'
import config from './src/aws-exports'
Amplify.configure(config)
// Pages
import Results from './Results';
import Scanner from './Scanner';
import Settings from './Settings';
import Stats from './Stats';
import AppContext from "./AppContext";
import * as SecureStore from 'expo-secure-store';
import 'react-native-get-random-values';
import { v4 as uuidv4 } from 'uuid';
function ScannerStackScreen() {
return (
<Stack.Navigator screenOptions={{ headerShown: false }}>
<Stack.Screen name="Scanner" component={Scanner} />
<Stack.Screen name="Results" component={Results} />
</Stack.Navigator>
);
}
async function checkForUUID() {
let result = await SecureStore.getItemAsync('secure_deviceid');
if (result === null) {
let uuid = uuidv4();
await SecureStore.setItemAsync('secure_deviceid', JSON.stringify(uuid));
let fetchUUID = await SecureStore.getItemAsync('secure_deviceid');
console.log(fetchUUID)
}
}
const App = () => {
// Global settings for all pages.
// Keeps track of set accessibility settings in a session.
// TODO: make data persistent.
const [soundIsEnabled, setSoundIsEnabled] = useState(false);
const soundToggleSwitch = () => setSoundIsEnabled(previousState => !previousState);
const [readIsEnabled, setReadIsEnabled] = useState(false);
const readToggleSwitch = () => setReadIsEnabled(previousState => !previousState);
const [darkIsEnabled, setDarkIsEnabled] = useState(false);
const darkToggleSwitch = () => setDarkIsEnabled(previousState => !previousState);
const [largeIsEnabled, setLargeIsEnabled] = useState(false);
const largeToggleSwitch = () => setLargeIsEnabled(previousState => !previousState);
const settings = {
soundEnabled: soundIsEnabled,
readEnabled: readIsEnabled,
darkEnabled: darkIsEnabled,
largeEnabled: largeIsEnabled,
soundToggleSwitch,
readToggleSwitch,
darkToggleSwitch,
largeToggleSwitch,
};
if (settings.darkEnabled) {
var darkText = "#fff"
} else {
var darkText = "#2F2F2F"
}
checkForUUID();
return (
<AppContext.Provider value={settings}>
<NavigationContainer>
<Tab.Navigator
screenOptions={({ route }) => ({
tabBarIcon: ({ focused, color, size }) => {
if (route.name === 'Scan') {
return (
<Ionicons
name={'barcode'}
size={size}
color={color}
/>
);
} else if (route.name === 'Stats') {
return (
<Ionicons
name={'ios-analytics-outline'}
size={size}
color={color}
/>
);
} else if (route.name === 'Settings') {
return (
<Ionicons
name={'ios-settings'}
size={size}
color={color}
/>
);
}else if (route.name === 'Statistics') {
return (
<Ionicons
name={'bar-chart'}
size={size}
color={color}
/>
);
}
},
tabBarInactiveTintColor: 'gray',
tabBarActiveTintColor: '#45B972',
})}
>
<Tab.Screen
name="Scan"
component={ScannerStackScreen}
options={settings.darkEnabled ? {
headerStyle: {
backgroundColor: '#16131D',
},
headerTintColor: '#fff',
} : {}}
/>
<Tab.Screen
name="Stats"
component={Stats}
options={settings.darkEnabled ? {
headerStyle: {
backgroundColor: '#16131D',
},
headerTintColor: '#fff',
} : {}}
/>
<Tab.Screen
name="Settings"
component={Settings}
options={settings.darkEnabled ? {
headerStyle: {
backgroundColor: '#16131D',
},
headerTintColor: '#fff',
} : {}}
/>
</Tab.Navigator>
</NavigationContainer>
</AppContext.Provider>
);
};
export default App;