diff --git a/Libraries/Lists/VirtualizedList.js b/Libraries/Lists/VirtualizedList.js index 2fad4637e6c57f..efce2bed49bfcd 100644 --- a/Libraries/Lists/VirtualizedList.js +++ b/Libraries/Lists/VirtualizedList.js @@ -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, diff --git a/Libraries/Lists/__tests__/VirtualizedList-test.js b/Libraries/Lists/__tests__/VirtualizedList-test.js index e05f68ee8708aa..45858695abbe8b 100644 --- a/Libraries/Lists/__tests__/VirtualizedList-test.js +++ b/Libraries/Lists/__tests__/VirtualizedList-test.js @@ -137,6 +137,20 @@ describe('VirtualizedList', () => { expect(component).toMatchSnapshot(); }); + it('scrollToEnd works with null list', () => { + const listRef = React.createRef(null); + ReactTestRenderer.create( + } + getItem={(data, index) => data[index]} + getItemCount={data => 0} + ref={listRef} + />, + ); + listRef.current.scrollToEnd(); + }); + it('renders empty list with empty component', () => { const component = ReactTestRenderer.create(