Projekt

Obecné

Profil

Stáhnout (3.25 KB) Statistiky
| Větev: | Tag: | Revize:
1 b7014ba2 Schwobik
import { createNativeStackNavigator } from "@react-navigation/native-stack"
2
import { NavigationContainer } from "@react-navigation/native"
3
import { IconButton } from "native-base"
4
import { AntDesign } from "@expo/vector-icons"
5
import { createDrawerNavigator } from "@react-navigation/drawer"
6
import { useSelector } from "react-redux"
7
import { RootState } from "../stores/store"
8 ddc84a2f Schwobik
import { nativeBaseTheme } from "../theme/nativeBaseTheme"
9
import HomePage from "../pages/HomePage"
10
import LoginPage from "../pages/LoginPage"
11
import SearchPage from "../pages/SearchPage"
12
import Logout from "../pages/Logout"
13 04928342 Schwobik
import ItemViewPage from "../pages/ItemViewPage"
14
15
export type RootDrawerParamList = {
16
    Home: undefined,
17
    Search: undefined,
18
    Logout: undefined,
19
    Item: { itemId: string },
20
    Login: undefined
21
}
22 b7014ba2 Schwobik
23
const Navigation = () => {
24 04928342 Schwobik
    const Drawer = createDrawerNavigator<RootDrawerParamList>()
25 b7014ba2 Schwobik
    const loggedIn = useSelector((state: RootState) => state.user.loggedIn)
26
27
    return (
28
        <NavigationContainer>
29
            <Drawer.Navigator useLegacyImplementation
30
                screenOptions={({ navigation }) => ({
31
                    headerStyle: {
32 e49b1f44 Schwobik
                        backgroundColor: nativeBaseTheme.colors.primary[800],
33 b7014ba2 Schwobik
                    },
34
                    headerTintColor: '#fff',
35
                    headerTitleStyle: {
36
                        fontWeight: 'bold',
37
                    },
38
                    headerRight: () => (
39
                        <IconButton
40
                            onPress={() => navigation.navigate("Search")}
41
                            title="Info"
42
                            color="#fff"
43
                            _icon={{
44
                                as: AntDesign,
45
                                name: "search1",
46
                                color: "white"
47
                            }}
48
                        />
49
                    ),
50
                })}
51
            >
52
                {loggedIn ? (
53
                    <>
54
                        <Drawer.Screen
55
                            name="Home"
56
                            component={HomePage}
57
                            options={{
58
                                title: 'My home'
59
                            }}
60
                        />
61
                        <Drawer.Screen
62
                            name="Search"
63
                            component={SearchPage}
64
                        />
65 ddc84a2f Schwobik
                        <Drawer.Screen
66
                            name="Logout"
67
                            component={Logout}
68
                        />
69 04928342 Schwobik
                        <Drawer.Screen
70
                            name={"Item"}
71
                            component={ItemViewPage}
72
                            options={{ drawerItemStyle: { display: "none" } }}
73
                        />
74 b7014ba2 Schwobik
                    </>
75
                ) : (
76
                    <Drawer.Screen
77
                        name="Login"
78
                        component={LoginPage}
79
                        options={({ navigation }) => ({
80
                            headerRight: () => (
81
                                <></>
82
                            )
83
                        })}
84
                    />
85
                )}
86
            </Drawer.Navigator>
87
        </NavigationContainer>
88
    )
89
90
}
91
92
export default Navigation