-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
181 lines (171 loc) · 5.54 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
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
import React from "react";
import PropTypes from "prop-types";
import { View, StyleSheet, Text, TouchableOpacity, Modal, SafeAreaView, FlatList } from "react-native";
export default class CustomPicker extends React.Component {
state = {
visible: false,
};
/**
* Key extractor for `FlatList`.
*/
_keyExtractor = (item, index) => index.toString();
render() {
return (
<React.Fragment>
<TouchableOpacity activeOpacity={this.props.activeOpacity} onPress={() => this.hideShowModal(!this.state.visible)} style={[styles.container, this.props.containerStyle]}>
<View style={styles.placeholderView}>
<Text style={styles.selectedItem} numberOfLines={1}>
{this.props.value ? this.props.value : this.props.placeholder}
</Text>
</View>
<View style={styles.iconView} >
<Icons {...this.props.iconProps} />
</View>
</TouchableOpacity>
<Modal visible={this.state.visible} animationType="none" transparent={true}>
<View style={styles.blurView} />
<SafeAreaView style={styles.modalContainer}>
<TouchableOpacity style={styles.list} onPress={this.closeModal} activeOpacity={1}>
<View style={styles.itemsContainer}>
<TouchableOpacity style={styles.listHeader} activeOpacity={1}>
<Text style={styles.headerText}>{this.props.placeholder}</Text>
<TouchableOpacity onPress={this.closeModal} style={{ width: 20, height: 20 }} >
<Icons type={Icons.IconNames.Close} color={colors.white} height={13} width={13} />
</TouchableOpacity>
</TouchableOpacity>
<FlatList
data={this.props.items}
renderItem={this.renderItem}
bounces={false}
showsVerticalScrollIndicator={false}
keyExtractor={this._keyExtractor}
extraData={this.props.value}
/>
</View>
</TouchableOpacity>
</SafeAreaView>
</Modal>
</React.Fragment>
);
}
hideShowModal = (visible) => {
this.setState({ visible });
}
closeModal = () => this.hideShowModal(false);
renderItem = ({ item, index }) => (
<TouchableOpacity style={styles.itemView} onPress={() => this.handleItemPress(item.value, index)}>
<Text style={styles.itemLabel} numberOfLines={1}>{item.label}</Text>
<View style={styles.radioView}>
{this.props.value === item.value && <View style={styles.innerRadioView} />}
</View>
</TouchableOpacity>
);
handleItemPress = (value, index) => {
this.props.onValueChange(value, index);
}
}
const styles = StyleSheet.create({
container: {
backgroundColor: "#fff",
paddingVertical: 15,
paddingHorizontal: 10,
flexDirection: "row",
},
iconView: {
width: 20,
alignItems: "center",
},
placeholderView: {
flex: 1,
},
selectedItem: {
color: "#000",
},
modalContainer: {
flex: 1,
justifyContent: "center",
marginBottom: 10,
},
blurView: {
backgroundColor: "#000",
flex: 1,
opacity: .5,
position: 'absolute',
width: "100%",
},
list: {
padding: 30,
justifyContent: 'center',
alignItems: "center",
height: "100%",
},
itemsContainer: {
backgroundColor: "#fff",
width: "100%",
maxWidth: 350,
elevation: 4,
shadowColor: "#000",
shadowOffset: { width: 0, height: 1 },
shadowOpacity: 0.5,
shadowRadius: 5,
marginBottom: 15,
},
listHeader: {
padding: 15,
backgroundColor: "purple",
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
},
headerText: {
color: "#fff",
flex: 1,
fontSize: 15,
},
itemView: {
padding: 15,
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
flex: 1,
borderBottomWidth: 0.5,
borderColor: "#ccc"
},
radioView: {
borderWidth: 1,
borderColor: "#000",
borderRadius: 30,
width: 25,
height: 25,
padding: 5
},
innerRadioView: {
backgroundColor: "purple",
borderRadius: 30,
width: "100%",
height: "100%",
},
itemLabel: {
color: "#000",
flex: 1,
paddingRight: 5,
}
});
CustomPicker.defaultProps = {
iconProps: {
/* type: Icons.IconNames.DownArrow, */
width: 15,
height: 15,
color: "#000",
},
activeOpacity: 0.2,
};
CustomPicker.propTypes = {
placeholder: PropTypes.string,
onValueChange: PropTypes.func,
value: PropTypes.string,
items: PropTypes.array,
iconProps: PropTypes.object,
containerStyle: PropTypes.object,
activeOpacity: PropTypes.number,
};