Skip to content

Commit b1f0f9e

Browse files
committed
fix bugs
1 parent 06ae750 commit b1f0f9e

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

index.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,14 @@ export default class PickerAndroid extends React.Component{
5050

5151
componentWillReceiveProps(nextProps){
5252
this.setState(this._stateFromProps(nextProps));
53-
this.length = this.state.items.length;
5453
}
5554

5655
_stateFromProps(props){
5756
let selectedIndex = 0;
5857
let items = [];
5958
let pickerStyle = props.pickerStyle;
6059
let itemStyle = props.itemStyle;
61-
let onValueChange = typeof props.onValueChange === function ? props.onValueChange : function(){};
60+
let onValueChange = props.onValueChange;
6261
React.Children.forEach(props.children, (child, index) => {
6362
child.props.value === props.selectedValue && ( selectedIndex = index );
6463
items.push({value: child.props.value, label: child.props.label});
@@ -110,23 +109,23 @@ export default class PickerAndroid extends React.Component{
110109
}
111110

112111
moveUp(){
113-
this._moveTo(Math.max(this.index - 1, 0));
112+
this._moveTo(Math.max(this.state.items.index - 1, 0));
114113
}
115114

116115
moveDown() {
117-
this._moveTo(Math.min(this.index + 1, this.length - 1));
116+
this._moveTo(Math.min(this.index + 1, this.state.items.length - 1));
118117
}
119118

120119
_handlePanResponderMove(evt, gestureState){
121-
let dy = gestureState.dy, index = this.index;
120+
let dy = gestureState.dy;
122121
if(this.isMoving) {
123122
return;
124123
}
125124
// turn down
126125
if(dy > 0) {
127126
this._move(dy > this.index * 40 ? this.index * 40 : dy);
128127
}else{
129-
this._move(dy < (this.index - this.length + 1) * 40 ? (this.index - this.length + 1) * 40 : dy);
128+
this._move(dy < (this.index - this.state.items.length + 1) * 40 ? (this.index - this.state.items.length + 1) * 40 : dy);
130129
}
131130
}
132131

@@ -144,9 +143,8 @@ export default class PickerAndroid extends React.Component{
144143
onPanResponderRelease: this._handlePanResponderRelease.bind(this),
145144
onPanResponderMove: this._handlePanResponderMove.bind(this)
146145
});
147-
this.index = this.state.selectedIndex;
148-
this.length = this.state.items.length;
149146
this.isMoving = false;
147+
this.index = this.state.selectedIndex;
150148
}
151149

152150
componentWillUnmount(){
@@ -191,7 +189,7 @@ export default class PickerAndroid extends React.Component{
191189
//but PickerIOS only passed value, so we set label to be the second argument
192190
//add by zooble @2015-12-10
193191
var curItem = this.state.items[this.index];
194-
this.state.onValueChange(curItem.value, curItem.label);
192+
this.state.onValueChange && this.state.onValueChange(curItem.value, curItem.label);
195193
}
196194

197195
render(){

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-picker-android",
3-
"version": "0.3.3",
3+
"version": "0.3.4",
44
"description": "react-native-picker-android",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)