Projekt

Obecné

Profil

« Předchozí | Další » 

Revize b7014ba2

Přidáno uživatelem Schwobik před téměř 2 roky(ů)

Drawer navigation design template
re #10345

Zobrazit rozdíly:

App.tsx
1
import { StatusBar } from 'expo-status-bar'
2
import { StyleSheet, Text, View } from 'react-native'
1
import 'react-native-gesture-handler'
2
import { StyleSheet} from 'react-native'
3 3
import { NativeBaseProvider, Box } from "native-base"
4
import LoginPage from './src/pages/LoginPage'
5 4
import { Provider } from "react-redux"
6 5
import store from "./src/stores/store"
6
import Navigation from "./src/components/Navigation"
7 7

  
8 8
export default function App() {
9 9
  return (
10 10
      <Provider store={store}>
11 11
          <NativeBaseProvider>
12
            <LoginPage />
12
              <Navigation/>
13 13
          </NativeBaseProvider>
14 14
      </Provider>
15 15
  )
babel.config.js
1 1
module.exports = function(api) {
2
  api.cache(true);
2
  api.cache(false);
3 3
  return {
4 4
    presets: ['babel-preset-expo'],
5
    plugins: ['react-native-reanimated/plugin'],
5 6
  };
6 7
};
package.json
9 9
    "web": "expo start --web"
10 10
  },
11 11
  "dependencies": {
12
    "@react-navigation/drawer": "^6.6.2",
13
    "@react-navigation/native": "^6.1.6",
14
    "@react-navigation/native-stack": "^6.9.12",
12 15
    "@reduxjs/toolkit": "^1.9.3",
13 16
    "axios": "^1.3.4",
14 17
    "expo": "~48.0.9",
......
16 19
    "native-base": "^3.4.28",
17 20
    "react": "18.2.0",
18 21
    "react-dom": "^18.2.0",
19
    "react-native": "0.71.4",
22
    "react-native": "0.71.6",
20 23
    "react-native-deck-swiper": "^2.0.13",
24
    "react-native-gesture-handler": "~2.9.0",
25
    "react-native-reanimated": "~2.14.4",
21 26
    "react-native-safe-area-context": "4.5.0",
27
    "react-native-screens": "~3.20.0",
22 28
    "react-native-svg": "13.4.0",
23 29
    "react-redux": "^8.0.5",
24 30
    "redux": "^4.2.1",
src/components/Navigation.tsx
1
import { createNativeStackNavigator } from "@react-navigation/native-stack"
2
import { NavigationContainer } from "@react-navigation/native"
3
import HomePage from "../pages/HomePage"
4
import LoginPage from "../pages/LoginPage"
5
import { IconButton } from "native-base"
6
import { AntDesign } from "@expo/vector-icons"
7
import SearchPage from "../pages/SearchPage"
8
import { createDrawerNavigator } from "@react-navigation/drawer"
9
import { useSelector } from "react-redux"
10
import { RootState } from "../stores/store"
11

  
12
const Navigation = () => {
13
    const Drawer = createDrawerNavigator()
14
    const loggedIn = useSelector((state: RootState) => state.user.loggedIn)
15

  
16
    return (
17
        <NavigationContainer>
18
            <Drawer.Navigator useLegacyImplementation
19
                screenOptions={({ navigation }) => ({
20
                    headerStyle: {
21
                        backgroundColor: '#f4511e',
22
                    },
23
                    headerTintColor: '#fff',
24
                    headerTitleStyle: {
25
                        fontWeight: 'bold',
26
                    },
27
                    headerRight: () => (
28
                        <IconButton
29
                            onPress={() => navigation.navigate("Search")}
30
                            title="Info"
31
                            color="#fff"
32
                            _icon={{
33
                                as: AntDesign,
34
                                name: "search1",
35
                                color: "white"
36
                            }}
37
                        />
38
                    ),
39
                })}
40
            >
41
                {loggedIn ? (
42
                    <>
43
                        <Drawer.Screen
44
                            name="Home"
45
                            component={HomePage}
46
                            options={{
47
                                title: 'My home'
48
                            }}
49
                        />
50
                        <Drawer.Screen
51
                            name="Search"
52
                            component={SearchPage}
53
                        />
54
                    </>
55
                ) : (
56
                    <Drawer.Screen
57
                        name="Login"
58
                        component={LoginPage}
59
                        options={({ navigation }) => ({
60
                            headerRight: () => (
61
                                <></>
62
                            )
63
                        })}
64
                    />
65
                )}
66
            </Drawer.Navigator>
67
        </NavigationContainer>
68
    )
69

  
70
}
71

  
72
export default Navigation
src/pages/HomePage.tsx
1
import { Center, Image, Text } from "native-base"
2

  
3
const HomePage = () => {
4
    return (
5
        <Center>
6
            <Text>Home Page</Text>
7
            <Image
8
                source={{uri: "http:/147.228.173.159/static/home/Rudolf-Aachen-crop.png"}}
9
                w={"100%"}
10
                h={"50%"}
11
                alt={"Rudolf-Aachen"}
12
            />
13
        </Center>
14
    )
15
}
16

  
17
export default HomePage
src/pages/SearchPage.tsx
1
import { Center, Text } from "native-base"
2

  
3
const SearchPage = () => {
4

  
5
    return (
6
        <Center>
7
            <Text>Search Page</Text>
8
        </Center>
9
    )
10
}
11

  
12
export default SearchPage

Také k dispozici: Unified diff