Projekt

Obecné

Profil

Stáhnout (3.74 KB) Statistiky
| Větev: | Tag: | Revize:
1
import {createNativeStackNavigator} from "@react-navigation/native-stack"
2
import {NavigationContainer} from "@react-navigation/native"
3
import {IconButton, Stack} 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

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

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

    
29
    return (
30
        <NavigationContainer>
31
            <Stack.Navigator initialRouteName="Home"
32
                              screenOptions={({navigation}) => ({
33
                                  headerStyle: {
34
                                      backgroundColor: nativeBaseTheme.colors.primary[800],
35
                                  },
36
                                  headerTintColor: '#fff',
37
                                  headerTitleStyle: {
38
                                      fontWeight: 'bold',
39
                                  },
40
                                  headerRight: () => (
41
                                      <IconButton
42
                                          onPress={() => navigation.navigate("Search", {inventoryId: null})}
43
                                          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
                        <Stack.Screen
57
                            name="Home"
58
                            component={HomePage}
59
                            options={{
60
                                title: 'My home'
61
                            }}
62
                        />
63
                        <Stack.Screen
64
                            name="Search"
65
                            component={SearchPage}
66
                            initialParams={{inventoryId: null}}
67
                        />
68
                        <Stack.Screen
69
                            name={"Notes"}
70
                            component={NotesViewPage}
71
                        />
72
                        <Stack.Screen
73
                            name="Logout"
74
                            component={Logout}
75
                        />
76
                        <Stack.Screen
77
                            name={"Item"}
78
                            component={ItemViewPage}
79
                        />
80
                    </>
81
                ) : (
82
                    <Stack.Screen
83
                        name="Login"
84
                        component={LoginPage}
85
                        options={({navigation}) => ({
86
                            headerRight: () => (
87
                                <></>
88
                            )
89
                        })}
90
                    />
91
                )}
92
            </Stack.Navigator>
93
        </NavigationContainer>
94
    )
95

    
96
}
97

    
98
export default Navigation
(5-5/7)