diff --git a/packages/virtualized-lists/Lists/VirtualizedList.js b/packages/virtualized-lists/Lists/VirtualizedList.js index 031267465af8..9d207739a3df 100644 --- a/packages/virtualized-lists/Lists/VirtualizedList.js +++ b/packages/virtualized-lists/Lists/VirtualizedList.js @@ -1152,13 +1152,6 @@ class VirtualizedList extends StateSafePureComponent< } return cloneElement(element, { - onLayout: (event: LayoutChangeEvent) => { - this._onLayoutEmpty(event); - // $FlowFixMe[prop-missing] React.Element internal inspection - if (element.props.onLayout) { - element.props.onLayout(event); - } - }, // $FlowFixMe[prop-missing] React.Element internal inspection style: StyleSheet.compose(inversionStyle, element.props.style), }); @@ -1695,10 +1688,6 @@ class VirtualizedList extends StateSafePureComponent< this._maybeCallOnEdgeReached(); }; - _onLayoutEmpty = (e: LayoutChangeEvent) => { - this.props.onLayout && this.props.onLayout(e); - }; - _getFooterCellKey(): string { return this._getCellKey() + '-footer'; } diff --git a/packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js b/packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js index 5bc0254c7127..0b39177a1e62 100644 --- a/packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js +++ b/packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js @@ -373,7 +373,7 @@ describe('VirtualizedList', () => { expect(result).toBe(fragment); }); - it('empty component clones the element and adds onLayout and style props if not a Fragment', () => { + it('empty component clones the element and adds the style prop if not a Fragment', () => { const listRef = createRef(); const element =
Test
; const inversionStyle = {transform: [{scaleY: -1}]}; @@ -396,14 +396,14 @@ describe('VirtualizedList', () => { inversionStyle, ); - // The result should be a cloned element with additional props + // The result should be a cloned element with the inversion style expect(result).not.toBe(element); expect(result.props).toEqual( expect.objectContaining({ - onLayout: expect.any(Function), style: inversionStyle, }), ); + expect(result.props.onLayout).toBeUndefined(); }); it('empty component preserves original onLayout handler if present', () => { @@ -433,10 +433,39 @@ describe('VirtualizedList', () => { // Call the onLayout handler result.props.onLayout({nativeEvent: {layout: {width: 100, height: 100}}}); - // Both the original and the new onLayout should be called + // The original onLayout should still be called expect(originalOnLayout).toHaveBeenCalled(); }); + it('does not call onLayout with the layout of ListEmptyComponent', () => { + const listRef = createRef(); + const onLayout = jest.fn(); + const emptyOnLayout = jest.fn(); + const element =
Empty
; + + act(() => { + create( + data[index]} + getItemCount={data => data.length} + renderItem={({item}) => } + />, + ); + }); + + const result = listRef.current._renderEmptyComponent(element, null); + result.props.onLayout({ + nativeEvent: {layout: {x: 24, y: 24, width: 338, height: 66}}, + }); + + expect(emptyOnLayout).toHaveBeenCalledTimes(1); + expect(onLayout).not.toHaveBeenCalled(); + }); + it('returns the viewableItems correctly in the onViewableItemsChanged callback after changing the data', async () => { const ITEM_HEIGHT = 800; let data = [{key: 'i1'}, {key: 'i2'}, {key: 'i3'}];