Skip to content

VirtualizedList + getItemLayout only renders initialNumToRender items #15734

@PublicParadise

Description

@PublicParadise

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

  1. react-native -v: 0.47.2
  2. node -v: v6.10.3
  3. npm -v: 3.10.10
  4. yarn --version: n/a

Then, specify:

  • Target Platform: iOS
  • Development Operating System: macOS
  • Build tools: Xcode

Steps to Reproduce

(Write your steps here:)

  1. Create a component with a FlatList w/t getItemLayout, i.e.
<FlatList
            ref={ref => { const anyRef: any = ref; this._flatList = anyRef }}
            data={data}
            renderItem={this._renderItem}
            onViewableItemsChanged={this._onViewableItemsChanged}
            getItemLayout={this._getItemLayout}
            initialNumToRender={10}
          />

I am using the standard getItemLayout:

getItemLayout={(data, index) => (
  {length: ITEM_HEIGHT, offset: ITEM_HEIGHT * index, index}
)}
  1. Provide a data source that has more than initialNumToRender items
  2. Render and scroll to bottom

Expected Behavior

(Write what you thought would happen.)

All items are rendered.

Actual Behavior

Only initialNumToRender items are rendered.

(Write what happened. Add screenshots!)

Reproducible Demo

The bug is in VirtualizedList:

const onLayout =
      getItemLayout && !parentProps.debug && !fillRateHelper.enabled()
        ? undefined
        : this.props.onLayout;

The fix is:

const onLayout = this.props.onLayout;

You need onLayout because somebody needs to call _onCellLayout(e, key, ii).

(Paste the link to an example project and exact instructions to reproduce the issue.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions