-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
110 lines (97 loc) · 3.38 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
import { StatusBar } from 'expo-status-bar';
import Login from "./screens/Login";
import Posts from "./screens/Posts";
import {createNativeStackNavigator} from "@react-navigation/native-stack";
import {NavigationContainer, getFocusedRouteNameFromRoute} from "@react-navigation/native";
import PostDetail from "./screens/PostDetail";
import AppContext from "./context/AppContext";
import Profile from "./screens/Profile";
import PostForm from "./screens/PostForm";
import {createBottomTabNavigator} from "@react-navigation/bottom-tabs";
import {FontAwesome} from '@expo/vector-icons';
import {useContext, useEffect} from "react";
import UserContext from "./context/UserContext";
import {navigationRef} from "./routing";
import {ActionSheetProvider} from "@expo/react-native-action-sheet";
const Stack = createNativeStackNavigator();
const Tab = createBottomTabNavigator();
function Home(){
return(
<ActionSheetProvider>
<Tab.Navigator
screenOptions={({route})=>({
tabBarActiveTintColor: 'blue',
tabBarInactiveTintColor: 'gray',
tabBarIcon: ({color, size})=>{
const iconName =
(route.name === 'Posts' && 'feed') ||
(route.name === 'PostForm' && 'plus-square') ||
(route.name === 'Profile' && 'user');
return <FontAwesome name={iconName} size={size} color={color}/>
}
})}>
<Stack.Screen
name='Posts'
component={Posts}
options={{headerShown:false}}
/>
<Stack.Screen
name='Profile'
component={Profile}
options={{headerShown:false}}
/>
<Stack.Screen
name='PostForm'
component={PostForm}
options={{
headerShown:false,
tabBarLabel : 'Add Post'}}
/>
</Tab.Navigator>
</ActionSheetProvider>
)
}
function Navigator(){
const {user, getToken} = useContext(UserContext);
useEffect(()=>{
getToken();
},[])
return(
<NavigationContainer ref={navigationRef}>
<StatusBar style='inverted'/>
<Stack.Navigator initialRouteName={
user.token.length? 'Home' : 'Login'
}>
<Stack.Screen
name='Home'
component={Home}
options={({route})=>({
headerTitle:getFocusedRouteNameFromRoute(route),
})}
/>
<Stack.Screen
name='Login'
component={Login}
options={{
headerStyle:{
backgroundColor:'lightgrey',
},
headerTintColor:'gray',
headerTitleStyle:{
fontWeight:'bold',
color:'#76BA99'
}
}}
/>
<Stack.Screen name='PostDetail' component={PostDetail}/>
</Stack.Navigator>
</NavigationContainer>
)
}
export default function App() {
return (
<AppContext>
<Navigator/>
</AppContext>
);
}