Projekt

Obecné

Profil

Stáhnout (5.16 KB) Statistiky
| Větev: | Tag: | Revize:
1 7410d6c1 Michal Schwob
import {createNativeStackNavigator} from "@react-navigation/native-stack"
2
import {NavigationContainer} from "@react-navigation/native"
3 7bfa1542 Michal Schwob
import {HStack, IconButton, Stack, VStack} from "native-base"
4 7410d6c1 Michal Schwob
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
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 7410d6c1 Michal Schwob
export type RootStackParamList = {
17 04928342 Schwobik
    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 7410d6c1 Michal Schwob
    const Stack = createNativeStackNavigator<RootStackParamList>()
27 b7014ba2 Schwobik
    const loggedIn = useSelector((state: RootState) => state.user.loggedIn)
28
29
    return (
30
        <NavigationContainer>
31 7410d6c1 Michal Schwob
            <Stack.Navigator initialRouteName="Home"
32 7bfa1542 Michal Schwob
                             screenOptions={ ({ navigation }) => ( {
33
                                 headerStyle: {
34
                                     backgroundColor: nativeBaseTheme.colors.primary[800],
35
                                 },
36
                                 headerTintColor: '#fff',
37
                                 headerTitleStyle: {
38
                                     fontWeight: 'bold',
39
                                 },
40
                                 headerRight: () => (
41
                                     <HStack space={ 0 } alignItems="end" marginRight={-3}>
42
                                         <IconButton
43
                                             onPress={() => navigation.navigate("Notes", {inventoryId: null})}
44
                                             title="Info"
45
                                             color="#fff"
46
                                             _icon={{
47
                                                 as: AntDesign,
48
                                                 name: "message1",
49
                                                 color: "white"
50
                                             }}
51
                                         />
52
                                         <IconButton
53
                                             onPress={ () => navigation.navigate("Search", { inventoryId: null }) }
54
                                             title="Info"
55
                                             color="#fff"
56
                                             _icon={ {
57
                                                 as: AntDesign,
58
                                                 name: "search1",
59
                                                 color: "white"
60
                                             } }
61
                                         />
62
                                         <IconButton
63
                                             onPress={() => navigation.navigate("Logout", {inventoryId: null})}
64
                                             title="Info"
65
                                             color="#fff"
66
                                             _icon={{
67
                                                 as: AntDesign,
68
                                                 name: "logout",
69
                                                 color: "white"
70
                                             }}
71
                                         />
72
                                     </HStack>
73
                                 ),
74
                             } ) }
75 b7014ba2 Schwobik
            >
76 7bfa1542 Michal Schwob
                { loggedIn ? (
77 b7014ba2 Schwobik
                    <>
78 7410d6c1 Michal Schwob
                        <Stack.Screen
79 b7014ba2 Schwobik
                            name="Home"
80 7bfa1542 Michal Schwob
                            component={ HomePage }
81
                            options={ {
82 b7014ba2 Schwobik
                                title: 'My home'
83 7bfa1542 Michal Schwob
                            } }
84 b7014ba2 Schwobik
                        />
85 7410d6c1 Michal Schwob
                        <Stack.Screen
86 b7014ba2 Schwobik
                            name="Search"
87 7bfa1542 Michal Schwob
                            component={ SearchPage }
88
                            initialParams={ { inventoryId: null } }
89 b7014ba2 Schwobik
                        />
90 7410d6c1 Michal Schwob
                        <Stack.Screen
91 7bfa1542 Michal Schwob
                            name={ "Notes" }
92
                            component={ NotesViewPage }
93 3218402b Schwobik
                        />
94 7410d6c1 Michal Schwob
                        <Stack.Screen
95 ddc84a2f Schwobik
                            name="Logout"
96 7bfa1542 Michal Schwob
                            component={ Logout }
97 ddc84a2f Schwobik
                        />
98 7410d6c1 Michal Schwob
                        <Stack.Screen
99 7bfa1542 Michal Schwob
                            name={ "Item" }
100
                            component={ ItemViewPage }
101 04928342 Schwobik
                        />
102 b7014ba2 Schwobik
                    </>
103
                ) : (
104 7410d6c1 Michal Schwob
                    <Stack.Screen
105 b7014ba2 Schwobik
                        name="Login"
106 7bfa1542 Michal Schwob
                        component={ LoginPage }
107
                        options={ ({ navigation }) => ( {
108 b7014ba2 Schwobik
                            headerRight: () => (
109
                                <></>
110
                            )
111 7bfa1542 Michal Schwob
                        } ) }
112 b7014ba2 Schwobik
                    />
113 7bfa1542 Michal Schwob
                ) }
114 7410d6c1 Michal Schwob
            </Stack.Navigator>
115 b7014ba2 Schwobik
        </NavigationContainer>
116
    )
117
118
}
119
120
export default Navigation