From aa10b3f2936f13bb54ba188d6e70cb897a022632 Mon Sep 17 00:00:00 2001 From: Rahul kishan M Date: Wed, 20 Mar 2019 07:50:59 -0700 Subject: [PATCH] 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 && } ``` [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 --- Libraries/Components/Picker/PickerIOS.ios.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Libraries/Components/Picker/PickerIOS.ios.js b/Libraries/Components/Picker/PickerIOS.ios.js index 1f47a53a97a11e..28514b0bfbba62 100644 --- a/Libraries/Components/Picker/PickerIOS.ios.js +++ b/Libraries/Components/Picker/PickerIOS.ios.js @@ -91,16 +91,18 @@ class PickerIOS extends React.Component { 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}; }