-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.jsx
More file actions
71 lines (66 loc) · 2.44 KB
/
Copy pathApp.jsx
File metadata and controls
71 lines (66 loc) · 2.44 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
import { useState, useEffect, useMemo } from 'react';
import { createAuthContext } from './lib/context/authContext';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { NavigationContainer, DefaultTheme } from '@react-navigation/native';
import LoadingScreen from './screens/LoadingScreen';
import LoginScreen from './screens/LoginScreen';
import HomeScreen from './screens/HomeScreen';
import DeviceInfoScreen from './screens/DeviceInfoScreen';
import DeviceEventsScreen from './screens/DeviceEventsScreen';
import 'react-native-gesture-handler';
import { useStyles } from './style/useStyles';
import { useColorScheme } from 'react-native';
import TripInfoScreen from './screens/TripInfoScreen';
import { createDevicesContext } from './lib/context/devicesContext';
const Stack = createNativeStackNavigator();
const App = () => {
const { AuthContext, ...authContextValue } = createAuthContext();
const { connected, loggedIn } = authContextValue;
const [ styles ]= useStyles();
const theme = useColorScheme();
const devicesContext = createDevicesContext();
const { DevicesContext } = devicesContext;
const Theme = useMemo(() => ({
...DefaultTheme,
colors: {
...DefaultTheme.colors,
primary: styles.fg,
background: styles.bg,
card: styles.colors.opacity01[theme],
text: styles.fg,
border: styles.colors.gray[theme],
notification: styles.bg,
dark: theme === 'dark'
}
}), [ theme, styles ]);
return (
<AuthContext.Provider value={authContextValue}>
<DevicesContext.Provider value={devicesContext}>
<NavigationContainer theme={Theme}>
<Stack.Navigator>
{
// not connected to the server
!connected ? (
<Stack.Screen name="LoadingScreen" component={LoadingScreen} options={{headerShown: false}} />
) :
// user not logged in
!loggedIn ? (
(<Stack.Screen name="Přihlášení" component={LoginScreen} options={{ headerShown: false }} />)
) :
// authenticated
(<>
<Stack.Screen name="HomeScreen" component={HomeScreen} options={{
headerShown: false
}} />
<Stack.Screen name="DeviceInfoScreen" component={DeviceInfoScreen} />
<Stack.Screen name="DeviceEventsScreen" component={DeviceEventsScreen} />
<Stack.Screen name="TripInfoScreen" component={TripInfoScreen} />
</>)
}
</Stack.Navigator>
</NavigationContainer>
</DevicesContext.Provider>
</AuthContext.Provider>
)
}
export default App;