Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions packages/virtualized-lists/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
});
Expand Down Expand Up @@ -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';
}
Expand Down
37 changes: 33 additions & 4 deletions packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <div>Test</div>;
const inversionStyle = {transform: [{scaleY: -1}]};
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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 = <div onLayout={emptyOnLayout}>Empty</div>;

act(() => {
create(
<VirtualizedList
ref={listRef}
data={[]}
onLayout={onLayout}
ListEmptyComponent={element}
getItem={(data, index) => data[index]}
getItemCount={data => data.length}
renderItem={({item}) => <item value={item.key} />}
/>,
);
});

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'}];
Expand Down
Loading