Skip to content

Commit f4932e8

Browse files
Merge pull request #380 from marcocesarato/copilot/fix-getitemlayout-arguments
Fix getItemLayout to receive actual data array instead of empty array
2 parents 6e9f79b + 4b69f1c commit f4932e8

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/BigList.jsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class BigList extends PureComponent {
8585
};
8686
}
8787
const self = BigList;
88-
const layoutItemHeight = self.getItemHeight(itemHeight, getItemLayout);
88+
const layoutItemHeight = self.getItemHeight(itemHeight, getItemLayout, data, sections);
8989
const sectionLengths = self.getSectionLengths(sections, data);
9090
const processor = new BigListProcessor({
9191
sections: sectionLengths,
@@ -160,11 +160,15 @@ class BigList extends PureComponent {
160160
* Get item height.
161161
* @param {number} itemHeight
162162
* @param {function|null|undefined} getItemLayout
163+
* @param {array|null|undefined} data
164+
* @param {array[]|object|null|undefined} sections
163165
* @return {null|*}
164166
*/
165-
static getItemHeight(itemHeight, getItemLayout) {
167+
static getItemHeight(itemHeight, getItemLayout, data = null, sections = null) {
166168
if (getItemLayout) {
167-
const itemLayout = getItemLayout([], 0);
169+
// Pass the actual data array to getItemLayout (sections takes precedence over data)
170+
const dataArray = sections || data || [];
171+
const itemLayout = getItemLayout(dataArray, 0);
168172
return itemLayout.length;
169173
}
170174
if (itemHeight) {
@@ -178,8 +182,8 @@ class BigList extends PureComponent {
178182
* @return {null|*}
179183
*/
180184
getItemHeight() {
181-
const { itemHeight, getItemLayout } = this.props;
182-
return this.constructor.getItemHeight(itemHeight, getItemLayout);
185+
const { itemHeight, getItemLayout, data, sections } = this.props;
186+
return this.constructor.getItemHeight(itemHeight, getItemLayout, data, sections);
183187
}
184188

185189
/**

0 commit comments

Comments
 (0)