forked from kacgrzes/react-native-menu
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.js
More file actions
Latest commit
185 lines (180 loc) · 5.2 KB
/
Copy pathExample.js
File metadata and controls
185 lines (180 loc) · 5.2 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
'use strict';
constReact=require('react');
constReactNative=require('react-native');
const{
ScrollView,
StyleSheet,
Text,
View
}=ReactNative;
importMenu,{
MenuContext,
MenuOptions,
MenuOption,
MenuTrigger
}from'react-native-menu';
constExample=React.createClass({
componentDidMount(){
// We can use the public context API to open/close/toggle the menu.
//setInterval(() => {
// this.refs.MenuContext.toggleMenu('menu1');
//}, 2000);
},
getInitialState(){
return{
message: 'Try clicking the top-right menus',
firstMenuDisabled: false,
dropdownSelection: '-- Choose --'
};
},
setMessage(value){
if(typeofvalue==='string'){
this.setState({message: `You selected "${value}"`});
}else{
this.setState({message: `Woah!\n\nYou selected an object:\n\n${JSON.stringify(value)}`});
}
returnvalue!=='do not close';
},
setFirstMenuDisabled(disabled){
this.setState({
message: `First menu is ${disabled ? 'disabled' : 'enabled'}`,
firstMenuDisabled: disabled
});
returnfalse;
},
render(){
return(
<MenuContextstyle={{flex: 1}}ref="MenuContext">
<Viewstyle={styles.topbar}>
<MenuonSelect={this.setMessage}>
<MenuTriggerdisabled={this.state.firstMenuDisabled}style={styles.menuTrigger}>
<Textstyle={styles.menuTriggerText}>OPEN FIRST MENU</Text>
</MenuTrigger>
<MenuOptionsstyle={styles.menuOptions}>
<MenuOptionvalue="normal">
<Text>Normal option</Text>
</MenuOption>
<MenuOptionvalue="do not close">
<Text>Does not close menu</Text>
</MenuOption>
<MenuOptionvalue="disabled"disabled={true}>
<Textstyle={styles.disabled}>Disabled option</Text>
</MenuOption>
<Viewstyle={styles.divider}/>
<MenuOptionvalue={{message: 'Hello World!'}}>
<Text>Option with object value</Text>
</MenuOption>
</MenuOptions>
</Menu>
</View>
<Viewstyle={[styles.topbar,{backgroundColor: '#333'}]}>
<MenuonSelect={this.setFirstMenuDisabled}>
<MenuTriggerstyle={styles.menuTrigger}>
<Textstyle={styles.menuTriggerText}>OPEN SECOND MENU</Text>
</MenuTrigger>
<MenuOptions>
{
this.state.firstMenuDisabled
? (
<MenuOptionvalue={false}>
<Text>enable first menu</Text>
</MenuOption>
)
: (
<MenuOptionvalue={true}>
<Text>disable first menu</Text>
</MenuOption>
)
}
</MenuOptions>
</Menu>
</View>
<Viewstyle={styles.content}>
<Textstyle={styles.contentText}>
{this.state.message}
</Text>
</View>
<Viewstyle={styles.content}>
<Textstyle={styles.contentText}>
You can also make it a dropdown
</Text>
<Menustyle={styles.dropdown}onSelect={(value)=>this.setState({dropdownSelection: value})}>
<MenuTrigger>
<Text>{this.state.dropdownSelection}</Text>
</MenuTrigger>
<MenuOptionsoptionsContainerStyle={styles.dropdownOptions}
renderOptionsContainer={(options)=><ScrollView><Text>CHOOSE SOMETHING....</Text>{options}</ScrollView>}>
<MenuOptionvalue="Option One">
<Text>Option One</Text>
</MenuOption>
<MenuOptionvalue="Option Two">
<Text>Option Two</Text>
</MenuOption>
<MenuOptionvalue="Option Three">
<Text>Option Three</Text>
</MenuOption>
<MenuOptionvalue="Option Four">
<Text>Option Four</Text>
</MenuOption>
<MenuOptionvalue="Option Five">
<Text>Option Five</Text>
</MenuOption>
</MenuOptions>
</Menu>
</View>
</MenuContext>
);
}
});
conststyles=StyleSheet.create({
topbar: {
flexDirection: 'row',
justifyContent: 'flex-end',
backgroundColor: 'black',
paddingHorizontal: 5,
paddingVertical: 10
},
menuTrigger: {
flexDirection: 'row',
paddingHorizontal: 10
},
menuTriggerText: {
color: 'lightgrey',
fontWeight: '600',
fontSize: 20
},
disabled: {
color: '#ccc'
},
divider: {
marginVertical: 5,
marginHorizontal: 2,
borderBottomWidth: 1,
borderColor: '#ccc'
},
content: {
backgroundColor: 'white',
paddingHorizontal: 10,
paddingTop: 20,
paddingBottom: 30,
borderBottomWidth: 1,
borderColor: '#ccc'
},
contentText: {
fontSize: 18
},
dropdown: {
width: 300,
borderColor: '#999',
borderWidth: 1,
padding: 5
},
dropdownOptions: {
marginTop: 30,
borderColor: '#ccc',
borderWidth: 2,
width: 300,
height: 200
}
});
module.exports=Example;