diff --git a/Libraries/Lists/VirtualizedList.js b/Libraries/Lists/VirtualizedList.js index 0a02fb1ef15..77b69cd72ac 100644 --- a/Libraries/Lists/VirtualizedList.js +++ b/Libraries/Lists/VirtualizedList.js @@ -1754,7 +1754,7 @@ class VirtualizedList extends React.PureComponent { // we'll wipe out the initialNumToRender rendered elements starting at initialScrollIndex. // So let's wait until we've scrolled the view to the right place. And until then, // we will trust the initialScrollIndex suggestion. - if (!this.props.initialScrollIndex || this._scrollMetrics.offset) { + if (!this.props.initialScrollIndex || this._hasDoneInitialScroll) { newState = computeWindowedRenderLimits( this.props.data, this.props.getItemCount, diff --git a/Libraries/Lists/__tests__/VirtualizedList-test.js b/Libraries/Lists/__tests__/VirtualizedList-test.js index a7589992564..9f902f180c7 100644 --- a/Libraries/Lists/__tests__/VirtualizedList-test.js +++ b/Libraries/Lists/__tests__/VirtualizedList-test.js @@ -862,40 +862,7 @@ it('does not adjust render area until content area layed out', () => { expect(component).toMatchSnapshot(); }); -it('does not adjust render area with non-zero initialScrollIndex until scrolled', () => { - const items = generateItems(20); - const ITEM_HEIGHT = 10; - - let component; - ReactTestRenderer.act(() => { - component = ReactTestRenderer.create( - , - ); - }); - - ReactTestRenderer.act(() => { - simulateLayout(component, { - viewport: {width: 10, height: 50}, - content: {width: 10, height: 200}, - }); - performAllBatches(); - }); - - // Layout information from before the time we scroll to initial index may not - // correspond to the area "initialScrollIndex" points to. Expect only the 5 - // initial items (starting at initialScrollIndex) to be rendered after - // processing all batch work, even though the windowSize allows for more. - expect(component).toMatchSnapshot(); -}); - -it('adjusts render area with non-zero initialScrollIndex after scrolled', () => { +it('adjusts render area with non-zero initialScrollIndex', () => { const items = generateItems(20); const ITEM_HEIGHT = 10; @@ -919,7 +886,6 @@ it('adjusts render area with non-zero initialScrollIndex after scrolled', () => content: {width: 10, height: 200}, }); - simulateScroll(component, {x: 0, y: 10}); performAllBatches(); }); @@ -928,6 +894,55 @@ it('adjusts render area with non-zero initialScrollIndex after scrolled', () => expect(component).toMatchSnapshot(); }); +it('renders new items when data is updated with non-zero initialScrollIndex', () => { + const items = generateItems(2); + const ITEM_HEIGHT = 10; + + let component; + ReactTestRenderer.act(() => { + component = ReactTestRenderer.create( + , + ); + }); + + ReactTestRenderer.act(() => { + simulateLayout(component, { + viewport: {width: 10, height: 50}, + content: {width: 10, height: 200}, + }); + performAllBatches(); + }); + + const newItems = generateItems(4); + + ReactTestRenderer.act(() => { + component.update( + , + ); + }); + + ReactTestRenderer.act(() => { + performAllBatches(); + }); + + // We expect all the items to be rendered + expect(component).toMatchSnapshot(); +}); + it('renders initialNumToRender cells when virtualization disabled', () => { const items = generateItems(10); const ITEM_HEIGHT = 10; diff --git a/Libraries/Lists/__tests__/__snapshots__/VirtualizedList-test.js.snap b/Libraries/Lists/__tests__/__snapshots__/VirtualizedList-test.js.snap index ad93703101b..7c8cbb8edd6 100644 --- a/Libraries/Lists/__tests__/__snapshots__/VirtualizedList-test.js.snap +++ b/Libraries/Lists/__tests__/__snapshots__/VirtualizedList-test.js.snap @@ -1600,7 +1600,7 @@ exports[`VirtualizedList warns if both renderItem or ListItemComponent are speci `; -exports[`adjusts render area with non-zero initialScrollIndex after scrolled 1`] = ` +exports[`adjusts render area with non-zero initialScrollIndex 1`] = ` `; -exports[`does not adjust render area with non-zero initialScrollIndex until scrolled 1`] = ` - - - - - - - - - - - - - - - - - - - - - -`; - exports[`does not over-render when there is less than initialNumToRender cells 1`] = ` `; +exports[`renders new items when data is updated with non-zero initialScrollIndex 1`] = ` + + + + + + + + + + + + + + + + +`; + exports[`renders no spacers up to initialScrollIndex on first render when virtualization disabled 1`] = `