forked from lesliesam/react-native-wheel-picker
-
Notifications
You must be signed in to change notification settings - Fork 15
/
picker.js
63 lines (55 loc) · 1.39 KB
/
picker.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
'use strict';
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import WheelCurvedPicker from './WheelCurvedPicker'
const PickerItem = WheelCurvedPicker.Item
import _ from 'lodash'
const styles = {
picker: {
backgroundColor: '#d3d3d3',
height: 220
},
picker__item: {
color: '#333333',
fontSize: 26
}
}
export default class Picker extends Component {
constructor(props) {
super(props);
this.state = {
selectedValue: this.props.selectedValue
};
}
static propTypes = {
onValueChange: PropTypes.func,
pickerData: PropTypes.array,
selectedValue: PropTypes.any
}
static defaultProps = {
pickerData: []
}
render() {
const { onValueChange, pickerData, itemStyle, style, ...props } = this.props
return (
<WheelCurvedPicker
{...props}
style={[styles.picker, style]}
itemStyle={_.assign({}, styles.picker__item, itemStyle)}
selectedValue={this.state.selectedValue}
onValueChange={(value) => {
this.setState({ selectedValue: value })
onValueChange && onValueChange( value )
}}
>
{pickerData.map((data, index) => (
<PickerItem key={index} value={data.value || data} label={data.label || data.toString()} />
)
)}
</WheelCurvedPicker>
)
}
getValue() {
return this.state.selectedValue
}
}