-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathdrawer-actions.js
executable file
·73 lines (67 loc) · 1.96 KB
/
drawer-actions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import * as React from 'react';
import { View, Button, Text } from 'react-native';
import { NavigationContainer, DrawerActions } from '@react-navigation/native';
import {
createDrawerNavigator,
DrawerContentScrollView,
DrawerItemList,
DrawerItem,
} from '@react-navigation/drawer';
function HomeScreen({ navigation }) {
const jumpToAction = DrawerActions.jumpTo('Profile', { user: 'Satya' });
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Home!</Text>
<Button
title="Open Drawer"
onPress={() => navigation.dispatch(DrawerActions.openDrawer())}
/>
<Button
title="Toggle Drawer"
onPress={() => navigation.dispatch(DrawerActions.toggleDrawer())}
/>
<Button
title="Jump to Profile"
onPress={() => navigation.dispatch(jumpToAction)}
/>
</View>
);
}
function ProfileScreen({ route }) {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Profile!</Text>
<Text>
{route?.params?.user ? route.params.user : 'No one'}'s profile
</Text>
</View>
);
}
function CustomDrawerContent(props) {
return (
<DrawerContentScrollView {...props}>
<DrawerItemList {...props} />
<DrawerItem
label="Close drawer"
onPress={() => props.navigation.dispatch(DrawerActions.closeDrawer())}
/>
<DrawerItem
label="Toggle drawer"
onPress={() => props.navigation.dispatch(DrawerActions.toggleDrawer())}
/>
</DrawerContentScrollView>
);
}
const Drawer = createDrawerNavigator();
export default function App() {
return (
<NavigationContainer>
<Drawer.Navigator
drawerContent={(props) => <CustomDrawerContent {...props} />}
>
<Drawer.Screen name="Home" component={HomeScreen} />
<Drawer.Screen name="Profile" component={ProfileScreen} />
</Drawer.Navigator>
</NavigationContainer>
);
}