-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
93 lines (84 loc) · 2.23 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
82
83
84
85
86
87
88
89
90
91
92
93
import React from 'react';
import { View, TouchableOpacity, ScrollView, StyleSheet, Text } from 'react-native';
import PropTypes from 'prop-types';
import Modal from 'react-native-modal';
class ModalSelector extends React.Component {
select(i){
const { labels, values, onSelect } = this.props;
if(values){
onSelect(values[i]);
}else {
onSelect(labels[i]);
}
}
render() {
const { isVisible, title, labels, values, headerColor } = this.props;
return (
<Modal isVisible={isVisible} style={ styles.modalStyle }>
<View style={{ flex: 1 }}>
<View style={[ styles.titleStyle, { backgroundColor: headerColor } ]}>
<Text style={[ styles.titleTextStyle ]}>{ this.props.title }</Text>
</View>
<ScrollView style={{ flex: 1 }}>
<View style={{ flex: 1 }}>
{
labels.map((label, i) => {
return (
<TouchableOpacity key={i} onPress={() => this.select(i)}>
<View style={ styles.labelContainerStyle }>
<Text style={ styles.labelTextStyle }>{ label }</Text>
</View>
</TouchableOpacity>
);
})
}
</View>
</ScrollView>
</View>
</Modal>
);
}
}
ModalSelector.defaultProps = {
isVisible: false,
title: 'Select',
labels: null,
values: null,
headerColor: '#CD2C2E',
};
ModalSelector.propTypes = {
isVisible: PropTypes.bool,
title: PropTypes.string,
labels: PropTypes.array,
values: PropTypes.array,
onSelect: PropTypes.func,
headerColor: PropTypes.string,
};
const styles = StyleSheet.create({
modalStyle: {
backgroundColor: 'white',
margin: 40,
alignItems: undefined,
justifyContent: undefined,
},
titleStyle: {
padding: 15,
},
titleTextStyle : {
color: 'white',
backgroundColor : 'transparent',
fontFamily: 'System',
fontSize: 20,
fontWeight: '600',
letterSpacing: 0.361328,
lineHeight:28,
},
labelContainerStyle: {
borderBottomColor: '#ececec',
borderBottomWidth: 1,
},
labelTextStyle: {
padding: 16,
}
});
export default ModalSelector;