@@ -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 ( ) {
0 commit comments