Skip to content
Closed
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
3 changes: 3 additions & 0 deletions Libraries/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ export default class VirtualizedList extends StateSafePureComponent<
scrollToEnd(params?: ?{animated?: ?boolean, ...}) {
const animated = params ? params.animated : true;
const veryLast = this.props.getItemCount(this.props.data) - 1;
if (veryLast < 0) {
return;
}
const frame = this.__getFrameMetricsApprox(veryLast, this.props);
const offset = Math.max(
0,
Expand Down
14 changes: 14 additions & 0 deletions Libraries/Lists/__tests__/VirtualizedList-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ describe('VirtualizedList', () => {
expect(component).toMatchSnapshot();
});

it('scrollToEnd works with null list', () => {
const listRef = React.createRef(null);
ReactTestRenderer.create(
<VirtualizedList
data={undefined}
renderItem={({item}) => <item value={item.key} />}
getItem={(data, index) => data[index]}
getItemCount={data => 0}
ref={listRef}
/>,
);
listRef.current.scrollToEnd();
});

it('renders empty list with empty component', () => {
const component = ReactTestRenderer.create(
<VirtualizedList
Expand Down