From 720e19525ede0570ea5fb5dfe4f29b696eb7c9be Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 23 Mar 2017 05:59:10 -0700 Subject: [PATCH] Picker (android): Convert children to an array before accessing with a position Summary: When using the following component, `this.props.children` is not a flat array. ``` js class Example extends Component { // ... render() { const values = ['1', '2']; return ( {values.map(value => { return ( ); })} ); } } ``` The resulting `this.props.children` is: ``` js [ (child), [ (child), (child), ], ]; ``` Therefor you can't use `this.props.children[2]` to get the last item. The Android version of the [Picker](https://facebook.github.io/react-native/do Closes https://github.com/facebook/react-native/pull/8153 Differential Revision: D4753480 Pulled By: javache fbshipit-source-id: deb0264746b39303e66c69c191af0c962db39085 --- Libraries/Components/Picker/PickerAndroid.android.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Libraries/Components/Picker/PickerAndroid.android.js b/Libraries/Components/Picker/PickerAndroid.android.js index 4c42c4e01..8be1579ae 100644 --- a/Libraries/Components/Picker/PickerAndroid.android.js +++ b/Libraries/Components/Picker/PickerAndroid.android.js @@ -116,7 +116,8 @@ class PickerAndroid extends React.Component { if (this.props.onValueChange) { var position = event.nativeEvent.position; if (position >= 0) { - var value = this.props.children[position].props.value; + var children = React.Children.toArray(this.props.children); + var value = children[position].props.value; this.props.onValueChange(value, position); } else { this.props.onValueChange(null, position);