Projekt

Obecné

Profil

Stáhnout (3.52 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 8e95f9c8 Schwobik
import HomePage from "./HomePage"
10
import LoginPage from "./LoginPage"
11
import SearchPage from "./SearchPage"
12
import Logout from "./Logout"
13
import ItemViewPage from "./ItemViewPage"
14 3fb38666 Schwobik
import NotesViewPage from "./NotesViewPage"
15 04928342 Schwobik
16
export type RootDrawerParamList = {
17
    Home: undefined,
18 8e95f9c8 Schwobik
    Search: { inventoryId: string | null },
19 04928342 Schwobik
    Logout: undefined,
20
    Item: { itemId: string },
21 3218402b Schwobik
    Login: undefined,
22
    Notes: undefined,
23 04928342 Schwobik
}
24 b7014ba2 Schwobik
25
const Navigation = () => {
26 04928342 Schwobik
    const Drawer = createDrawerNavigator<RootDrawerParamList>()
27 b7014ba2 Schwobik
    const loggedIn = useSelector((state: RootState) => state.user.loggedIn)
28
29
    return (
30
        <NavigationContainer>
31 17d84a83 Michal Schwob
            <Drawer.Navigator
32 b7014ba2 Schwobik
                screenOptions={({ navigation }) => ({
33
                    headerStyle: {
34 e49b1f44 Schwobik
                        backgroundColor: nativeBaseTheme.colors.primary[800],
35 b7014ba2 Schwobik
                    },
36
                    headerTintColor: '#fff',
37
                    headerTitleStyle: {
38
                        fontWeight: 'bold',
39
                    },
40
                    headerRight: () => (
41
                        <IconButton
42 cbf81c55 Schwobik
                            onPress={() => navigation.navigate("Search", {inventoryId: null})}
43 b7014ba2 Schwobik
                            title="Info"
44
                            color="#fff"
45
                            _icon={{
46
                                as: AntDesign,
47
                                name: "search1",
48
                                color: "white"
49
                            }}
50
                        />
51
                    ),
52
                })}
53
            >
54
                {loggedIn ? (
55
                    <>
56
                        <Drawer.Screen
57
                            name="Home"
58
                            component={HomePage}
59
                            options={{
60
                                title: 'My home'
61
                            }}
62
                        />
63
                        <Drawer.Screen
64
                            name="Search"
65
                            component={SearchPage}
66 84cc4e49 Michal Schwob
                            initialParams={{inventoryId: null}}
67 b7014ba2 Schwobik
                        />
68 3218402b Schwobik
                        <Drawer.Screen
69
                            name={"Notes"}
70
                            component={NotesViewPage}
71
                        />
72 ddc84a2f Schwobik
                        <Drawer.Screen
73
                            name="Logout"
74
                            component={Logout}
75
                        />
76 04928342 Schwobik
                        <Drawer.Screen
77
                            name={"Item"}
78
                            component={ItemViewPage}
79
                            options={{ drawerItemStyle: { display: "none" } }}
80
                        />
81 b7014ba2 Schwobik
                    </>
82
                ) : (
83
                    <Drawer.Screen
84
                        name="Login"
85
                        component={LoginPage}
86
                        options={({ navigation }) => ({
87
                            headerRight: () => (
88
                                <></>
89
                            )
90
                        })}
91
                    />
92
                )}
93
            </Drawer.Navigator>
94
        </NavigationContainer>
95
    )
96
97
}
98
99
export default Navigation