From bb05176a4bcac9545ebfc54cf75cdbf0fd7d1273 Mon Sep 17 00:00:00 2001 From: ifsnow Date: Fri, 23 Aug 2019 11:43:52 -0700 Subject: [PATCH] Better implementation for getItemCount on FlatList (#26164) Summary: Flatlist's `getItemCount` function is frequently called internally by VirtualizedList. As with other functions, we can remove unnecessary operations with the `numColumns` value. This makes it much more efficient. ## Changelog [Internal] [Changed] - Better implementation for getItemCount on FlatList Pull Request resolved: https://github.com/facebook/react-native/pull/26164 Test Plan: Not required Differential Revision: D16989335 Pulled By: sahrens fbshipit-source-id: b0075b2c2aeb9b9d7644c8bb18702a7cca8a4dce --- Libraries/Lists/FlatList.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Libraries/Lists/FlatList.js b/Libraries/Lists/FlatList.js index 3afed1ba5a7..f9fb2a6aca1 100644 --- a/Libraries/Lists/FlatList.js +++ b/Libraries/Lists/FlatList.js @@ -560,7 +560,12 @@ class FlatList extends React.PureComponent, void> { }; _getItemCount = (data: ?Array): number => { - return data ? Math.ceil(data.length / this.props.numColumns) : 0; + if (data) { + const {numColumns} = this.props; + return numColumns > 1 ? Math.ceil(data.length / numColumns) : data.length; + } else { + return 0; + } }; _keyExtractor = (items: ItemT | Array, index: number) => {