-
Notifications
You must be signed in to change notification settings - Fork 2
/
App.js
144 lines (128 loc) · 3.76 KB
/
App.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import React, { Component } from 'react';
import { Button, View, Text, Image, TouchableOpacity } from 'react-native';
import { createStackNavigator, createDrawerNavigator } from 'react-navigation'
// 1) The TouchableMenuIcon will always be displayed on the top-left hand side of the app
class TouchableMenuIcon extends Component {
toggleDrawer=()=>{
this.props.navigationProps.toggleDrawer();
}
render() {
return (
<View style={{flexDirection: 'row'}}>
<TouchableOpacity onPress={this.toggleDrawer.bind(this)} >
<Image
source={{uri : 'https://reactnativecode.com/wp-content/uploads/2018/04/hamburger_icon.png'}}
style={{ width: 25, height: 25, marginLeft: 5}}
/>
</TouchableOpacity>
</View>
);
}
}
// 2) Touching the menu icon opens up the SideMenu which you can style however you want
class SideMenu extends Component {
render() {
return (
<View style={{flex: 1, backgroundColor: 'white'}}>
<View style={{flexDirection: 'column', marginTop:30, justifyContent: 'space-around'}}>
<Button
title="Screen 1"
onPress={() => {
this.props.navigation.navigate('RootStackScreen1');
this.props.navigation.closeDrawer();
}}
/>
<Button
title="Screen 2"
onPress={() => {
this.props.navigation.navigate('RootStackScreen2');
this.props.navigation.closeDrawer();
}}
/>
<Button
title="Screen 3"
onPress={() => {
this.props.navigation.navigate('RootStackScreen3');
this.props.navigation.closeDrawer();
}}
/>
</View>
</View>
);
}
}
// 3) A navigation stack RootStack holds the 3 screens in this example
class RootStackScreen1 extends Component {
render() {
return (
<View style = {{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text style={{fontSize: 23}}> Root Stack: Screen 1</Text>
<Button
title="Next Screen"
onPress={() => {
this.props.navigation.navigate('RootStackScreen2');
}}
/>
</View>
);
}
}
class RootStackScreen2 extends Component {
render() {
return (
<View style = {{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text style={{fontSize: 23}}> Root Stack: Screen 2</Text>
<Button
title="Next Screen"
onPress={() => {
this.props.navigation.navigate('RootStackScreen3');
}}
/>
<Button
title="Previous Screen"
onPress={() => {
this.props.navigation.goBack();
}}
/>
</View>
);
}
}
class RootStackScreen3 extends Component {
render() {
return (
<View style = {{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text style={{fontSize: 23}}> Root Stack: Screen 3</Text>
<Button
title="Previous Screen"
onPress={() => {
this.props.navigation.goBack();
}}
/>
</View>
);
}
}
const RootStack = createStackNavigator(
{
RootStackScreen1: RootStackScreen1,
RootStackScreen2: RootStackScreen2,
RootStackScreen3: RootStackScreen3
},
{
initialRouteName: 'RootStackScreen1',
navigationOptions: ({ navigation }) => ({
title: "Root Stack",
headerLeft: <TouchableMenuIcon navigationProps={ navigation }/>
})
}
);
// 4) MyDrawerNavigator wraps the root stack and makes the side menu show up!
export default MyDrawerNavigator = createDrawerNavigator(
{
RootStack: RootStack,
},
{
contentComponent: SideMenu
}
);