From b454d31ab8d778c393a3a99869c50d1967baaaad Mon Sep 17 00:00:00 2001 From: Jimmy Mayoukou Date: Fri, 19 Feb 2016 06:49:41 -0800 Subject: [PATCH] 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 --- Libraries/Components/Picker/PickerAndroid.android.js | 4 ++-- Libraries/Picker/PickerIOS.ios.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Libraries/Components/Picker/PickerAndroid.android.js b/Libraries/Components/Picker/PickerAndroid.android.js index 71d7b35e81d1ea..797653d001df98 100644 --- a/Libraries/Components/Picker/PickerAndroid.android.js +++ b/Libraries/Components/Picker/PickerAndroid.android.js @@ -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); } } diff --git a/Libraries/Picker/PickerIOS.ios.js b/Libraries/Picker/PickerIOS.ios.js index 0aa82bb5f8f8bd..84bb1c0e7f0fdc 100644 --- a/Libraries/Picker/PickerIOS.ios.js +++ b/Libraries/Picker/PickerIOS.ios.js @@ -54,7 +54,7 @@ var PickerIOS = React.createClass({ }); return {selectedIndex, items}; }, - + render: function() { return ( @@ -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