diff --git a/Libraries/Lists/FlatList.js b/Libraries/Lists/FlatList.js index 11d34d07bdc90c..2ebd0f673ab004 100644 --- a/Libraries/Lists/FlatList.js +++ b/Libraries/Lists/FlatList.js @@ -499,8 +499,9 @@ class FlatList extends React.PureComponent, void> { if (numColumns > 1) { const ret = []; for (let kk = 0; kk < numColumns; kk++) { - const item = data[index * numColumns + kk]; - if (item != null) { + const itemIndex = index * numColumns + kk; + if (itemIndex < data.length) { + const item = data[itemIndex]; ret.push(item); } } diff --git a/Libraries/Lists/__tests__/FlatList-test.js b/Libraries/Lists/__tests__/FlatList-test.js index d8b523fd2203b6..5940928b1ad348 100644 --- a/Libraries/Lists/__tests__/FlatList-test.js +++ b/Libraries/Lists/__tests__/FlatList-test.js @@ -152,4 +152,35 @@ describe('FlatList', () => { expect(scrollRef.measureLayout).toBeInstanceOf(jest.fn().constructor); expect(scrollRef.measureInWindow).toBeInstanceOf(jest.fn().constructor); }); + + it('calls renderItem for all data items', () => { + const data = [ + {key: 'i1'}, + null, + undefined, + {key: 'i2'}, + null, + undefined, + {key: 'i3'}, + ]; + + const renderItemInOneColumn = jest.fn(); + ReactTestRenderer.create( + , + ); + + expect(renderItemInOneColumn).toHaveBeenCalledTimes(7); + + const renderItemInThreeColumns = jest.fn(); + + ReactTestRenderer.create( + , + ); + + expect(renderItemInThreeColumns).toHaveBeenCalledTimes(7); + }); });