Skip to content

Commit

Permalink
Null check on Picker Items (#24057)
Browse files Browse the repository at this point in the history
Summary:
when conditional rendering is used then picker breaks when the child is null in iOS

This conditional rendering inside Picker fails when "someBooleanValue" variable is false

```
{
   this.state.someBooleanValue && <Picker.Item label="value" value="value" />
}
```

[iOS] [Fixed] - null check on children by using filter
Pull Request resolved: #24057

Differential Revision: D14538337

Pulled By: cpojer

fbshipit-source-id: d9324671931b5f1dac65d8058d9aa957b650af25
  • Loading branch information
Rahulkishanm authored and facebook-github-bot committed Mar 20, 2019
1 parent 80743eb commit aa10b3f
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions Libraries/Components/Picker/PickerIOS.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,18 @@ class PickerIOS extends React.Component<Props, State> {
static getDerivedStateFromProps(props: Props): State {
let selectedIndex = 0;
const items = [];
React.Children.toArray(props.children).forEach(function(child, index) {
if (child.props.value === props.selectedValue) {
selectedIndex = index;
}
items.push({
value: child.props.value,
label: child.props.label,
textColor: processColor(child.props.color),
React.Children.toArray(props.children)
.filter(child => child !== null)
.forEach(function(child, index) {
if (child.props.value === props.selectedValue) {
selectedIndex = index;
}
items.push({
value: child.props.value,
label: child.props.label,
textColor: processColor(child.props.color),
});
});
});
return {selectedIndex, items};
}

Expand Down

0 comments on commit aa10b3f

Please sign in to comment.