Skip to content

Commit 720e195

Browse files
justimfacebook-github-bot
authored andcommitted
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 ( <Picker value={this.state.value} onValueChange={this.onValueChange.bind(this)} > <Picker.Item label="n/a" value={null} /> {values.map(value => { return ( <Picker.Item label={value} value={value} /> ); })} </Picker> ); } } ``` 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 #8153 Differential Revision: D4753480 Pulled By: javache fbshipit-source-id: deb0264746b39303e66c69c191af0c962db39085
1 parent 8a8f34a commit 720e195

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Libraries/Components/Picker/PickerAndroid.android.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ class PickerAndroid extends React.Component {
116116
if (this.props.onValueChange) {
117117
var position = event.nativeEvent.position;
118118
if (position >= 0) {
119-
var value = this.props.children[position].props.value;
119+
var children = React.Children.toArray(this.props.children);
120+
var value = children[position].props.value;
120121
this.props.onValueChange(value, position);
121122
} else {
122123
this.props.onValueChange(null, position);

0 commit comments

Comments
 (0)