-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathApp.tsx
128 lines (116 loc) · 3.5 KB
/
App.tsx
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
import { NavigationContainer, ParamListBase } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { useFonts } from 'expo-font';
import { NativeStackNavigationOptions } from '@react-navigation/native-stack';
import { SafeAreaView } from 'react-native';
import { StatusBar } from 'expo-status-bar';
import Login from '@screens/Login';
import Home from '@screens/Home';
import Task from '@screens/Task';
import { useState, useEffect } from 'react';
import { ThemeProvider } from '@contexts/ThemeContext';
import { AuthStorageContext } from '@contexts/AuthStorageContext';
import { TaskProvider } from '@contexts/TaskContext';
import { RecordProvider } from '@app/core/contexts/RecordContext';
import Accessibility from '@components/AccessibilityMenu';
import SafeAreaViewAndroid from '@components/SafeAreaViewAndroid';
import AuthStorage from '@utils/authStorage';
const Stack = createNativeStackNavigator<ParamListBase>();
const optionsPrimary: NativeStackNavigationOptions = {
animation: 'fade_from_bottom',
headerBackVisible: false,
headerShown: false,
headerTitleStyle: {
fontFamily: 'Poppins-Regular'
}
};
export default function App() {
const [loaded] = useFonts({
'Poppins-Regular': require('@fonts/Poppins/Poppins-Regular.ttf'),
'Poppins-Medium': require('@fonts/Poppins/Poppins-Medium.ttf'),
'Poppins-Bold': require('@fonts/Poppins/Poppins-Bold.ttf'),
'Roboto-Regular': require('@fonts/Roboto/Roboto-Regular.ttf'),
'Roboto-Medium': require('@fonts/Roboto/Roboto-Medium.ttf'),
'Roboto-Bold': require('@fonts/Roboto/Roboto-Bold.ttf'),
'Ubuntu-Regular': require('@fonts/Ubuntu/Ubuntu-Regular.ttf'),
'Ubuntu-Medium': require('@fonts/Ubuntu/Ubuntu-Medium.ttf'),
'Ubuntu-Bold': require('@fonts/Ubuntu/Ubuntu-Bold.ttf')
});
const [isLogged, setIsLogged] = useState(false);
const authStorage = new AuthStorage();
useEffect(() => {
authStorage.getAccessToken().then((token) => {
if (token) {
setIsLogged(true);
}
});
}, []);
if (!loaded) {
return null;
}
return (
<>
<StatusBar />
<SafeAreaView style={SafeAreaViewAndroid.AndroidSafeArea}>
<AuthStorageContext.Provider value={authStorage}>
<RecordProvider>
<TaskProvider>
<ThemeProvider>
<NavigationContainer>
<Stack.Navigator>
{!isLogged ? (
<>
<Stack.Screen
name="Login"
component={Login}
options={{
...optionsPrimary
}}
/>
<Stack.Screen
name="Home"
component={Home}
options={{
...optionsPrimary
}}
/>
</>
) : (
<>
<Stack.Screen
name="Home"
component={Home}
options={{
...optionsPrimary
}}
/>
<Stack.Screen
name="Login"
component={Login}
options={{
...optionsPrimary
}}
/>
</>
)}
<Stack.Screen
name="Task"
component={Task}
options={{
...optionsPrimary
}}
initialParams={{
taskOrder: 0
}}
/>
</Stack.Navigator>
<Accessibility />
</NavigationContainer>
</ThemeProvider>
</TaskProvider>
</RecordProvider>
</AuthStorageContext.Provider>
</SafeAreaView>
</>
);
}