mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-05-10 01:15:00 +08:00
Null check on Picker Items (#24057)
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: https://github.com/facebook/react-native/pull/24057
Differential Revision: D14538337
Pulled By: cpojer
fbshipit-source-id: d9324671931b5f1dac65d8058d9aa957b650af25
This commit is contained in:
committed by
Facebook Github Bot
parent
80743eb7b1
commit
aa10b3f293
@@ -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};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user