Projekt

Obecné

Profil

Stáhnout (3.66 KB) Statistiky
| Větev: | Tag: | Revize:
1
import {createNativeStackNavigator} from "@react-navigation/native-stack"
2
import {NavigationContainer} from "@react-navigation/native"
3
import {HamburgerIcon, HStack, IconButton, Menu, Pressable, Stack, View, VStack} 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
import {nativeBaseTheme} from "../theme/nativeBaseTheme"
9
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
import NotesViewPage from "./NotesViewPage"
15
import MenuComponent from "../components/navigation/MenuComponent"
16

    
17
export type RootStackParamList = {
18
    Home: undefined,
19
    Search: { inventoryId: string | null },
20
    Logout: undefined,
21
    Item: { itemId: string },
22
    Login: undefined,
23
    Notes: undefined,
24
}
25

    
26
const Navigation = () => {
27
    const Stack = createNativeStackNavigator<RootStackParamList>()
28
    const loggedIn = useSelector((state: RootState) => state.user.loggedIn)
29

    
30
    return (
31
        <NavigationContainer>
32
            <Stack.Navigator initialRouteName="Home"
33
                             screenOptions={ ({ navigation }) => ( {
34
                                 headerStyle: {
35
                                     backgroundColor: nativeBaseTheme.colors.primary[50],
36
                                 },
37
                                 headerTitleStyle: {
38
                                     fontWeight: 'bold',
39
                                     color: nativeBaseTheme.colors.primary[500],
40
                                 },
41
                                 headerTintColor: nativeBaseTheme.colors.primary[500],
42
                                 headerRight: () => (
43
                                     <MenuComponent navigation={navigation}/>
44
                                 ),
45
                                 contentStyle: {
46
                                     backgroundColor: nativeBaseTheme.colors.primary[50],
47
                                 },
48
                             } ) }
49
            >
50
                { loggedIn ? (
51
                    <>
52
                        <Stack.Screen
53
                            name="Home"
54
                            component={ HomePage }
55
                            options={ {
56
                                title: 'My home'
57
                            } }
58
                        />
59
                        <Stack.Screen
60
                            name="Search"
61
                            component={ SearchPage }
62
                            initialParams={ { inventoryId: null } }
63
                        />
64
                        <Stack.Screen
65
                            name={ "Notes" }
66
                            component={ NotesViewPage }
67
                        />
68
                        <Stack.Screen
69
                            name="Logout"
70
                            component={ Logout }
71
                        />
72
                        <Stack.Screen
73
                            name={ "Item" }
74
                            component={ ItemViewPage }
75
                        />
76
                    </>
77
                ) : (
78
                    <Stack.Screen
79
                        name="Login"
80
                        component={ LoginPage }
81
                        options={ ({ navigation }) => ( {
82
                            headerRight: () => (
83
                                <></>
84
                            )
85
                        } ) }
86
                    />
87
                ) }
88
            </Stack.Navigator>
89
        </NavigationContainer>
90
    )
91

    
92
}
93

    
94
export default Navigation
(5-5/7)