fix: fix virtualizedList scrollToEnd for 0 items (#36067)
Summary: Fixes https://github.com/facebook/react-native/issues/36066 ## Changelog [GENERAL] [FIXED] - VirtualizedList scrollToEnd with no data Pull Request resolved: https://github.com/facebook/react-native/pull/36067 Test Plan: Run `yarn test VirtualizedList-test` Reviewed By: jacdebug Differential Revision: D43041763 Pulled By: javache fbshipit-source-id: d4d5e871284708a89bf9911d82e9aa97d7625aca
This commit is contained in:
Родитель
34604fa8fd
Коммит
98009ad94b
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче