Skip to content

Conversation

@ish1416
Copy link
Contributor

@ish1416 ish1416 commented Nov 9, 2025

Summary:

Fixes #54409

When using initialScrollIndex with a FlatList where all items fit within the viewport, items before the initialScrollIndex were not being rendered. This caused missing items and incorrect rendering behavior.

Root Cause: The _initialRenderRegion method calculated the initial render region starting from initialScrollIndex without considering if the entire list could fit in the viewport. Additionally, the _createRenderMask method skipped the "scroll-to-top" optimization when initialScrollIndex > 0, preventing all items from being rendered.

Solution:

  • Modified _initialRenderRegion to render all items (0 to itemCount-1) when itemCount <= initialNumToRender and initialScrollIndex is set
  • Updated _createRenderMask to apply the scroll-to-top optimization for small lists even when initialScrollIndex > 0

Changelog:

[GENERAL] [FIXED] - Fix FlatList initialScrollIndex missing items when entire list fits in viewport

Test Plan:

Test Case 1: Bug Reproduction

<FlatList
  data={Array.from({length: 7}, (_, i) => ({id: i, title: `Item ${i}`}))}
  initialScrollIndex={4}
  initialNumToRender={10}
  renderItem={({item}) => <Text>{item.title}</Text>}
/>```
Before fix : Only renders items 4, 5, 6

After fix : Renders all items 0, 1, 2, 3, 4, 5, 6

Test Case 2: Large List (No Regression)

```javascript
<FlatList
  data={Array.from({length: 20}, (_, i) => ({id: i, title: `Item ${i}`}))}
  initialScrollIndex={10}
  initialNumToRender={10}
  renderItem={({item}) => <Text>{item.title}</Text>}
/>

- Fix setFeedbackUnderlay method to properly set view background
- Resolves issue where ripple drawable was created but not applied
- Fixes regression introduced by new background drawable system
- Addresses issue facebook#54372
- Fix _initialRenderRegion to render all items when itemCount <= initialNumToRender
- Fix _createRenderMask to apply scroll-to-top optimization for small lists with initialScrollIndex
- Resolves issue where items before initialScrollIndex were not rendered
- Ensures proper rendering order when entire list fits in viewport
- Addresses issue facebook#54409
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 9, 2025
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 9, 2025
- Fix missing items before initialScrollIndex when entire list fits in viewport
- Add validation for empty lists to prevent crashes
- Preserve large list performance and accessibility behavior

Fixes facebook#54409
- Limit fix to small lists (≤15 items) to preserve virtualization
- Require initialScrollIndex > 0 to maintain accessibility focus
- Prevent scroll UP issues and first item rendering problems
- Maintain original behavior for larger lists

Addresses reported issues while keeping the core bug fix
- Only apply fix when getItemLayout is provided to prevent virtualization issues
- Reduce item limit to 10 for more conservative approach
- Fixes scroll UP issues and jumping behavior without getItemLayout
- Maintains original behavior for lists without getItemLayout

Resolves scroll and focus issues while preserving the core bug fix
@JvmStatic
public fun setFeedbackUnderlay(view: View, drawable: Drawable?) {
ensureCompositeBackgroundDrawable(view).withNewFeedbackUnderlay(drawable)
view.background = ensureCompositeBackgroundDrawable(view).withNewFeedbackUnderlay(drawable)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this change is related to the list behavior. Could you revert this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this change is related to the list behavior. Could you revert this?

Hey actually i did this to resolve another issue that is #54455 .
can you check that PR too?

Copy link
Contributor Author

@ish1416 ish1416 Nov 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cipolleschi review that PR too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cipolleschi review that PR too and this one and merge it?

@cipolleschi If you want i can revert it here?

if (itemCount > 0 &&
itemCount <= Math.min(initialNumToRender, 10) &&
props.initialScrollIndex > 0 &&
props.getItemLayout != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you do a check here for getItemLayout?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flatlist with initialScrollIndex will cause missing items

4 participants