-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
81 lines (76 loc) · 2.31 KB
/
index.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
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import { View, TextInput, StyleSheet, TouchableOpacity, ViewPropTypes,Text,Modal,ScrollView } from 'react-native';
class MKMenu extends Component{
constructor(){
super();
this.state={
MKMenuVisible: true
}
}
render(){
let {modalTitle,data,clickMenu} = this.props;
const datas = data.map( (menu, index) => {
return(
<TouchableOpacity style={styles.MKMenuItem} onPress={ () => {
this.setState({ MKMenuVisible:false });
setTimeout(() =>{this.props.onPress(index, menu.menuTitle)},0)
}}>
<Text> {menu.menuIcon} {menu.menuTitle}</Text>
</TouchableOpacity>
)
})
return(
<Modal
animationType="slide"
transparent={true}
visible={this.state.MKMenuVisible}
>
<View style={{backgroundColor:'#000',width:'100%',height:'100%',opacity:0.4,position:'absolute'}}/>
<View style={styles.MKMenu}>
<View style={styles.MKMenuTitle}>
<Text style={{color:'#fff',fontSize:19}}> {modalTitle} </Text>
</View>
<View>
<ScrollView contentHeight={'20%'}>
{datas}
</ScrollView>
</View>
</View>
</Modal>
)
}
}
const styles = StyleSheet.create({
MKMenu:{
width:'80%',
maxHeight:'56%',
backgroundColor:'#fff',
alignSelf:'center',
marginTop:'50%',
borderRadius:30
},
MKMenuTitle:{
backgroundColor:'#38a9f6',
padding:10,
borderBottomWidth:1,
borderBottomColor:'#ddd',
borderTopLeftRadius:10,
borderTopRightRadius:10,
},
MKMenuItem:{
padding:15,
borderTopWidth:1,
borderTopColor:'#ecf0f1',
}
});
MKMenu.defaultProps={
modalTitle:'Select item',
onPress: (select) => console.log('Selected: ' + select)
}
MKMenu.propTypes={
modalTitle: PropTypes.string.isRequired,
data: PropTypes.object.isRequired,
onPress: PropTypes.func.isRequired,
}
export default MKMenu;