Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 7410d6c1

Přidáno uživatelem Michal Schwob před více než 1 rok

Added skeleton of Stack Navigation
re #10820

Zobrazit rozdíly:

src/pages/Navigation.tsx
1
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
import { nativeBaseTheme } from "../theme/nativeBaseTheme"
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 9
import HomePage from "./HomePage"
10 10
import LoginPage from "./LoginPage"
11 11
import SearchPage from "./SearchPage"
......
13 13
import ItemViewPage from "./ItemViewPage"
14 14
import NotesViewPage from "./NotesViewPage"
15 15

  
16
export type RootDrawerParamList = {
16
export type RootStackParamList = {
17 17
    Home: undefined,
18 18
    Search: { inventoryId: string | null },
19 19
    Logout: undefined,
......
23 23
}
24 24

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

  
29 29
    return (
30 30
        <NavigationContainer>
31
            <Drawer.Navigator useLegacyImplementation
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
                })}
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 53
            >
54 54
                {loggedIn ? (
55 55
                    <>
56
                        <Drawer.Screen
56
                        <Stack.Screen
57 57
                            name="Home"
58 58
                            component={HomePage}
59 59
                            options={{
60 60
                                title: 'My home'
61 61
                            }}
62 62
                        />
63
                        <Drawer.Screen
63
                        <Stack.Screen
64 64
                            name="Search"
65 65
                            component={SearchPage}
66 66
                            initialParams={{inventoryId: null}}
67 67
                        />
68
                        <Drawer.Screen
68
                        <Stack.Screen
69 69
                            name={"Notes"}
70 70
                            component={NotesViewPage}
71 71
                        />
72
                        <Drawer.Screen
72
                        <Stack.Screen
73 73
                            name="Logout"
74 74
                            component={Logout}
75 75
                        />
76
                        <Drawer.Screen
76
                        <Stack.Screen
77 77
                            name={"Item"}
78 78
                            component={ItemViewPage}
79
                            options={{ drawerItemStyle: { display: "none" } }}
80 79
                        />
81 80
                    </>
82 81
                ) : (
83
                    <Drawer.Screen
82
                    <Stack.Screen
84 83
                        name="Login"
85 84
                        component={LoginPage}
86
                        options={({ navigation }) => ({
85
                        options={({navigation}) => ({
87 86
                            headerRight: () => (
88 87
                                <></>
89 88
                            )
90 89
                        })}
91 90
                    />
92 91
                )}
93
            </Drawer.Navigator>
92
            </Stack.Navigator>
94 93
        </NavigationContainer>
95 94
    )
96 95

  

Také k dispozici: Unified diff