-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
116 lines (108 loc) · 3.12 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
import React, { useContext, useEffect } from "react";
import { DefaultTheme, NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import {
Provider as AuthProvider,
Context as AuthContext,
} from "./src/context/AuthContext";
import Login from "./src/Screens/Login";
import Register from "./src/Screens/Register";
import Home from "./src/Screens/Home";
import Profile from "./src/Screens/Profile";
import Friends from "./src/Screens/Friends";
import {
useFonts,
Inter_400Regular,
Inter_600SemiBold,
Inter_700Bold,
} from "@expo-google-fonts/inter";
import { THEME } from "./src/theme";
import Loading from "./src/components/Loading";
import { House, User, UsersThree } from "phosphor-react-native";
import { Provider as PostsProvider } from "./src/context/PostsContext";
import { navigationRef } from "./src/RootNavigation";
import { Provider as ProfilesProvider } from "./src/context/ProfilesContext";
const Stack = createNativeStackNavigator();
const Tab = createBottomTabNavigator();
const AppTheme = {
...DefaultTheme,
dark: true,
colors: {
...DefaultTheme.colors,
background: THEME.COLORS.BLACK,
},
};
function App() {
const { token, tryLocalLogin, isLoading } = useContext(AuthContext);
const [fontsLoaded] = useFonts({
Inter_400Regular,
Inter_600SemiBold,
Inter_700Bold,
});
useEffect(() => {
tryLocalLogin();
}, []);
if (!fontsLoaded || isLoading) {
return <Loading />;
}
return (
<NavigationContainer theme={AppTheme} ref={navigationRef}>
{!token ? (
<Stack.Navigator
screenOptions={{
headerShown: false,
}}
>
<Stack.Screen name="Login" component={Login} />
<Stack.Screen name="Register" component={Register} />
</Stack.Navigator>
) : (
<Tab.Navigator
screenOptions={{
tabBarStyle: {
backgroundColor: THEME.COLORS.BLACK,
borderTopColor: THEME.COLORS.GRAY_MEDIUM,
},
tabBarActiveTintColor: THEME.COLORS.CYAN,
tabBarShowLabel: false,
headerShown: false,
}}
>
<Tab.Screen
name="Home"
component={Home}
options={{
tabBarIcon: ({ color }) => <House size={32} color={color} />,
}}
/>
<Tab.Screen
name="Friends"
component={Friends}
options={{
tabBarIcon: ({ color }) => <UsersThree size={32} color={color} />,
}}
/>
<Tab.Screen
name="Profile"
component={Profile}
options={{
tabBarIcon: ({ color }) => <User size={32} color={color} />,
}}
/>
</Tab.Navigator>
)}
</NavigationContainer>
);
}
export default () => {
return (
<AuthProvider>
<PostsProvider>
<ProfilesProvider>
<App />
</ProfilesProvider>
</PostsProvider>
</AuthProvider>
);
};