mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Guard FlatList getItemCount() against incorrect data type
Summary: If FlatList is passed non-array data it will return `undefined` as the result of `getItemCount()` to VirtualizedList. This change makes it return `0` instead, to signify there are no valid items to attempt to accces. There are a set of invariants on properties passed to FlatList, to curb incorrect types at runtime, but there is existing code which runs into the condition. Changelog: [Internal][Fixed] - Guard FlatList getItemCount() against non-array data Reviewed By: javache Differential Revision: D38198351 fbshipit-source-id: 9efd0df7eeeba17078e2c838d470c4b0d621b9a0
This commit is contained in:
committed by
Facebook GitHub Bot
parent
f8e1fedf3d
commit
d574ea3526
@@ -511,7 +511,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
|
||||
};
|
||||
|
||||
_getItemCount = (data: ?Array<ItemT>): number => {
|
||||
if (data) {
|
||||
if (Array.isArray(data)) {
|
||||
const numColumns = numColumnsOrDefault(this.props.numColumns);
|
||||
return numColumns > 1 ? Math.ceil(data.length / numColumns) : data.length;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user