forked from M-Izadmehr/react-native-multiple-picker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
PickerCategory.js
93 lines (83 loc) · 2.53 KB
/
PickerCategory.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, {Component} from 'react';
import {Text, View, FlatList, TouchableWithoutFeedback} from 'react-native';
class PickerCategory extends Component {
constructor(props) {
super(props);
if(this.props.initValue){
var initValue = this.props.initValue[this.props.catId];
}
this.state = {
selectedId: initValue,
}
}
buttonPress = (item) => {
this.setState({selectedId: item.key});
this.props.onPress(item.key,this.props.catId);
};
renderItem = (item) => {
const {selectedId} = this.state;
const {items,textStyle,textStyleSelected} = styles;
const isSelected = selectedId === item.key;
let selectedItem = styles.selectedItemMiddle;
if (this.props.catId === 0) {
selectedItem = styles.selectedItemFirst;
} else if (this.props.catId === this.props.catNum-1) {
selectedItem = styles.selectedItemLast;
}
return (
<TouchableWithoutFeedback onPress={() => this.buttonPress(item)}>
<View style={[items,isSelected && selectedItem]}>
<Text style={[textStyle,isSelected && textStyleSelected]}>{item.label}</Text>
</View>
</TouchableWithoutFeedback>
);
};
render() {
return (
<View style={{flex: 1,width:'100%'}}>
<FlatList style={{flex: 1,width:'100%'}}
data={this.props.data}
removeClippedSubviews={true}
renderItem={({item}) => {
return this.renderItem(item)
}}
/>
</View>
);
}
}
const styles = {
items: {
paddingVertical: 10,
alignItems: 'center'
},
selectedItemFirst: {
elevation:5,
backgroundColor: '#fa986c',
borderBottomRightRadius: 40,
borderTopRightRadius: 40,
},
selectedItemLast: {
elevation:15,
backgroundColor: '#fa986c',
borderBottomLeftRadius: 40,
borderTopLeftRadius: 40,
},
selectedItemMiddle: {
elevation:15,
backgroundColor: '#fa986c',
borderBottomRightRadius: 40,
borderTopRightRadius: 40,
borderBottomLeftRadius: 40,
borderTopLeftRadius: 40,
},
textStyle:{
color: '#fff8',
fontSize: 20
},
textStyleSelected:{
color: '#fff',
fontSize: 25
},
};
export default PickerCategory;