Skip to content

Commit

Permalink
Fix PickerAndroid breaking when child is null. (#23884)
Browse files Browse the repository at this point in the history
Summary:
On conditional rendering if child is null then the PickerAndroid breaks.

when conditional rendering is used then picker breaks when the child is null.

This conditional rendering inside Picker fails when a is 1, because child will be null in PickerAndroid.android.js.

```
{
   this.state.a === 2 && <Picker.Item label="value" value="value" />
}
```
[ANDROID] [FIXED] - Filter props.children.
Pull Request resolved: #23884

Differential Revision: D14436860

Pulled By: cpojer

fbshipit-source-id: 6a8fca604acf77c20729f26a53cd7f67e514deac
  • Loading branch information
a-c-sreedhar-reddy authored and facebook-github-bot committed Mar 13, 2019
1 parent 3898ee3 commit 85e8b3e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Libraries/Components/Picker/PickerAndroid.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ class PickerAndroid extends React.Component<
if (this.props.onValueChange) {
const position = event.nativeEvent.position;
if (position >= 0) {
const children = React.Children.toArray(this.props.children);
const children = React.Children.toArray(this.props.children).filter(
item => item != null,
);
const value = children[position].props.value;
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was
* found when making Flow check .android.js files. */
Expand Down

0 comments on commit 85e8b3e

Please sign in to comment.