Add position to Picker onValueChange's call
Summary:According to the [docs](http://facebook.github.io/react-native/releases/0.20/docs/picker.html#onvaluechange), `Picker`'s `onValueChange` should be called with `itemValue` and `itemPosition` but currently only `itemValue` is passed. This PR fixes that. The position is passed as the 2nd parameter to not introduce any breaking change, and also to respect the current documentation. The documentation doesn't need to be changed as it will be correct with this PR, but maybe it needs to be updated until this is merged? Closes https://github.com/facebook/react-native/pull/5874 Differential Revision: D2953936 Pulled By: nicklockwood fb-gh-sync-id: b8c1283013d4c7ed315066d8750f601f76f6bbb2 shipit-source-id: b8c1283013d4c7ed315066d8750f601f76f6bbb2
This commit is contained in:
parent
f961b78c51
commit
b454d31ab8
|
@ -100,9 +100,9 @@ var PickerAndroid = React.createClass({
|
|||
var position = event.nativeEvent.position;
|
||||
if (position >= 0) {
|
||||
var value = this.props.children[position].props.value;
|
||||
this.props.onValueChange(value);
|
||||
this.props.onValueChange(value, position);
|
||||
} else {
|
||||
this.props.onValueChange(null);
|
||||
this.props.onValueChange(null, position);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ var PickerIOS = React.createClass({
|
|||
});
|
||||
return {selectedIndex, items};
|
||||
},
|
||||
|
||||
|
||||
render: function() {
|
||||
return (
|
||||
<View style={this.props.style}>
|
||||
|
@ -74,7 +74,7 @@ var PickerIOS = React.createClass({
|
|||
this.props.onChange(event);
|
||||
}
|
||||
if (this.props.onValueChange) {
|
||||
this.props.onValueChange(event.nativeEvent.newValue);
|
||||
this.props.onValueChange(event.nativeEvent.newValue, event.nativeEvent.newIndex);
|
||||
}
|
||||
|
||||
// The picker is a controlled component. This means we expect the
|
||||
|
|
Loading…
Reference in New Issue