From f2cd01e01a667f4cb58ced56ab4c4c6da7cd0427 Mon Sep 17 00:00:00 2001 From: Julien Brayere Date: Mon, 6 Feb 2023 12:43:26 +0100 Subject: [PATCH 1/3] fix: fix virtualizedList scrollToEnd for 0 items --- Libraries/Lists/VirtualizedList.js | 3 +++ 1 file changed, 3 insertions(+) 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, From 51193308fb088160e537648c64fc734559e2b342 Mon Sep 17 00:00:00 2001 From: Julien Brayere Date: Mon, 6 Feb 2023 12:51:07 +0100 Subject: [PATCH 2/3] tests: adding FlatList test --- Libraries/Lists/__tests__/FlatList-test.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Libraries/Lists/__tests__/FlatList-test.js b/Libraries/Lists/__tests__/FlatList-test.js index bc7c9d1faf16cc..6e37dfd124984b 100644 --- a/Libraries/Lists/__tests__/FlatList-test.js +++ b/Libraries/Lists/__tests__/FlatList-test.js @@ -74,6 +74,17 @@ describe('FlatList', () => { ); expect(component).toMatchSnapshot(); }); + it('scrollToEnd works with null list', () => { + const listRef = React.createRef(null); + ReactTestRenderer.create( + } + ref={listRef} + />, + ); + listRef.current.scrollToEnd(); + }); it('renders all the bells and whistles', () => { const component = ReactTestRenderer.create( Date: Mon, 6 Feb 2023 13:58:19 +0100 Subject: [PATCH 3/3] tests: moving test to virtualizedList --- Libraries/Lists/__tests__/FlatList-test.js | 11 ----------- Libraries/Lists/__tests__/VirtualizedList-test.js | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Libraries/Lists/__tests__/FlatList-test.js b/Libraries/Lists/__tests__/FlatList-test.js index 6e37dfd124984b..bc7c9d1faf16cc 100644 --- a/Libraries/Lists/__tests__/FlatList-test.js +++ b/Libraries/Lists/__tests__/FlatList-test.js @@ -74,17 +74,6 @@ describe('FlatList', () => { ); expect(component).toMatchSnapshot(); }); - it('scrollToEnd works with null list', () => { - const listRef = React.createRef(null); - ReactTestRenderer.create( - } - ref={listRef} - />, - ); - listRef.current.scrollToEnd(); - }); it('renders all the bells and whistles', () => { const component = ReactTestRenderer.create( { 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(