Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding prop getCellsInItemCount to VirtualizedList
getItemCount does not calculate the exact number of accessible collection Items (cells) of a virtualized list for example, a list can have 2 columns and 2 rows, but only 3 items. getItemCount would return the number of rows 2 and not the number of items 3. +--------+--------+ | item 1 | item 2 | +--------+--------+ | item 3 | | +--------+--------+ the result is calculated by dividing data.lenght / numColumns https://github.com/fabriziobertoglio1987/react-native/blob/3a11bff4be8ef30b73faad1167fe45ef0de6d2cc/Libraries/Lists/FlatList.js#L508-L515 ```javascript _getItemCount = (data: ?Array<ItemT>): number => { if (data) { const numColumns = numColumnsOrDefault(this.props.numColumns); return numColumns > 1 ? Math.ceil(data.length / numColumns) : data.length; } else { return 0; } }; ``` https://github.com/fabriziobertoglio1987/react-native-notes/blob/3a11bff4be8ef30b73faad1167fe45ef0de6d2cc/Libraries/Lists/VirtualizedList.js#L87-L91 ``` /** * The default accessor functions assume this is an Array<{key: string} | {id: string}> but you can override * getItem, getItemCount, and keyExtractor to handle any type of index-based data. */ data?: any, /** * Determines how many items are in the data blob. */ getItemCount: (data: any) => number, ``` this commit adds a prop getCellsInItemCount which calculates by default the correct number of items in a VirtualizedList when using data of type Array, but allows developers to over-ride this method and calculate the number of items/cells in the list with other data types.
- Loading branch information