Repository navigation
Expand file tree
/
Copy pathPicker.web.js
More file actions
112 lines (99 loc) · 2.8 KB
/
Copy pathPicker.web.js
File metadata and controls
112 lines (99 loc) · 2.8 KB
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
/**
* Copyright (c) 2015-present, Alibaba Group Holding Limited.
* All rights reserved.
*
* @providesModule ReactPicker
*/
'use strict';
import React, { Component, PropTypes } from 'react';
import StyleSheet from 'ReactStyleSheet';
import autobind from 'autobind-decorator';
import View from 'ReactView';
import Text from 'ReactText';
import TouchableWithoutFeedback from 'ReactTouchableWithoutFeedback';
const PICKER = 'picker';
class Picker extends Component {
static propTypes = {
onValueChange: PropTypes.func,
selectedValue: PropTypes.any, // string or integer basically
isRenderSelect: PropTypes.bool
}
static defaultProps = {
isRenderSelect: false
}
_onChange(event) {
if (this.props.onChange) {
this.props.onChange(event);
}
if (this.props.onValueChange) {
this.props.onValueChange(this.refs[PICKER].value);
}
}
render() {
if (this.props.isRenderSelect) {
return (
<select
ref={PICKER}
value={this.props.selectedValue}
style={{
color: 'inherit',
font: 'inherit',
...this.props.style}}
onChange={this._onChange}
>
{this.props.children}
</select>
);
} else {
let label;
if (this.props.children.length > 0) {
if (!!this.props.selectedValue) {
for (let i = 0; i < this.props.children.length; i++) {
if (this.props.selectedValue == this.props.children[i].props.value) {
label = this.props.children[i].props.label;
break;
}
}
} else {
label = this.props.children[0].props.label;
}
}
return (
<TouchableWithoutFeedback onPress={()=>this.refs[PICKER].click()}>
<View style={this.props.style}>
<Text ref={'picker_label'} style={{position:'absolute',top:0,left:0,right:0,bottom:0}}>{label}</Text>
<select
ref={PICKER}
value={this.props.selectedValue}
style={{
flex: 1,
opacity: 0,
}}
onChange={(event)=>{
let c = this.refs[PICKER];
let ct = c.options[c.selectedIndex].text;
this.setState({});
// this.refs.picker_label.refs.text.value = ct;
this._onChange(event);
} }
>
{this.props.children}
</select>
</View>
</TouchableWithoutFeedback>
);
}
}
};
Picker.Item = React.createClass({
propTypes: {
value: PropTypes.any, // string or integer basically
label: PropTypes.string,
},
render: function() {
return <option value={this.props.value}>{this.props.label}</option>;
},
});
autobind(Picker);
Picker.isReactNativeComponent = true;
export default Picker;