-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.js
72 lines (66 loc) · 2.31 KB
/
routes.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
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { Ionicons } from "@expo/vector-icons";
import HomePage from "./src/pages/HomePage";
import LoginPage from "./src/pages/LoginPage";
import RegisterPage from "./src/pages/RegisterPage";
import WriteThoughtPage from "./src/pages/WriteThoughtPage";
import { TransitionPresets } from "@react-navigation/stack";
import { useSelector } from "react-redux";
import ProfilePage from "./src/pages/ProfilePage";
const Tab = createBottomTabNavigator();
const Stack = createNativeStackNavigator();
const MainTabs = () => {
const { userInfo } = useSelector((state) => state.auth);
return (
<>
<Tab.Navigator
screenOptions={({ route }) => ({
headerShown: route.name === "Home", // header is only shown for homepage
// route.name === "Home" && "Thoughts..." ,
headerTitle: route.name === "Home" ? "Thoughts..." : null, // for homepage, show the title as "thoughts..."
tabBarIcon: ({ focused }) => {
let iconName;
if (route.name === "Home") {
iconName = focused ? "home" : "home-outline";
} else if (route.name === "Login") {
iconName = focused ? "log-in" : "log-in-outline";
} else if (route.name === "Profile") {
iconName = focused ? "people-sharp" : "people-outline";
}
return <Ionicons name={iconName} size={24} />;
},
})}
>
<Tab.Screen name="Home" component={HomePage} />
{userInfo ? (
<Tab.Screen name="Profile" component={ProfilePage} />
) : (
<Tab.Screen name="Login" component={LoginPage} />
)}
</Tab.Navigator>
</>
);
};
const Routes = () => {
return (
<Stack.Navigator
screenOptions={{
...TransitionPresets.ModalSlideFromBottomIOS,
}}
>
<Stack.Screen
name="MainTabs"
component={MainTabs}
options={{ headerShown: false }}
/>
<Stack.Screen name="Register" component={RegisterPage} />
<Stack.Screen
name="WriteThought"
component={WriteThoughtPage}
options={{ headerBackTitle: "Back" }}
/>
</Stack.Navigator>
);
};
export default Routes;