Commit d50fd1a
committed
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.1 parent 3a11bff commit d50fd1a
1 file changed
+18
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
| 97 | + | |
98 | 98 | | |
99 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
100 | 104 | | |
101 | 105 | | |
102 | 106 | | |
103 | 107 | | |
104 | | - | |
| 108 | + | |
105 | 109 | | |
106 | 110 | | |
107 | 111 | | |
| |||
1254 | 1258 | | |
1255 | 1259 | | |
1256 | 1260 | | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
1257 | 1268 | | |
1258 | 1269 | | |
1259 | 1270 | | |
1260 | 1271 | | |
1261 | 1272 | | |
1262 | 1273 | | |
1263 | 1274 | | |
| 1275 | + | |
1264 | 1276 | | |
1265 | | - | |
1266 | | - | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
1267 | 1281 | | |
1268 | 1282 | | |
1269 | 1283 | | |
| |||
0 commit comments