react / react/react-native

FlatList with initialScrollIndex skips earlier items when list fits viewport

未关闭
#56,237 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Component: FlatList Needs: Triage :mag:
主要语言
C++
星标
127k
派生
25.3k
平均合并
1 天 23 小时
30 天内合并 PR
4

描述

Description

If initialScrollIndex is set to a non-zero value and the list fits entirely on screen, items before that index are not rendered on Android.

You land at the correct index, but the items before it never appear and can’t be reached

Steps to reproduce
  1. Render a short FlatList so all items fit in the viewport (no scrolling)
  2. Set initialScrollIndex to something > 0
  3. Provide getItemLayout

The provided expo snack has a complete demo example with trigger buttons.

React Native Version

0.84.1

Affected Platforms

Runtime - Android

Output of npx @react-native-community/cli info
System:
  OS: Windows 11 10.0.26200
  CPU: "(16) x64 AMD Ryzen 7 6800H with Radeon Graphics         "
  Memory: 4.72 GB / 15.25 GB
Binaries:
  Node:
    version: 23.5.0
    path: C:\Program Files\nodejs\node.EXE
  Yarn:
    version: 1.22.22
    path: C:\Users\Andrei\AppData\Roaming\npm\yarn.CMD
  npm:
    version: 11.9.0
    path: C:\Program Files\nodejs\npm.CMD
  Watchman: Not Found
SDKs:
  Android SDK: Not Found
  Windows SDK:
    AllowAllTrustedApps: Enabled
    Versions:
      - 10.0.26100.0
IDEs:
  Android Studio: Not Found
  Visual Studio: Not Found
Languages:
  Java:
    version: 23.0.1
    path: C:\Program Files\Common Files\Oracle\Java\javapath\javac.EXE
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli":
    installed: 20.1.0
    wanted: 20.1.0
  react:
    installed: 19.2.3
    wanted: 19.2.3
  react-native:
    installed: 0.84.1
    wanted: 0.84.1
  react-native-windows: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found
Stacktrace or Logs
There is no crash or thrown error in this case.

This is a rendering issue:
MANDATORY Reproducer

https://snack.expo.dev/@andyhoover/flatlist-initialscrollindex-bug-2026

Screenshots and Videos
Image Image Image

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 Expo Snack 复现用例开始,检查 Android 上 FlatList 的行为:当 initialScrollIndex 非零、列表适合 viewport 且提供了 getItemLayout 时,情况如何。跟踪相关的 React Native Android 入口点,然后验证所有更早的项目都会被渲染并保持可访问,同时初始索引仍处于选中状态。

由索引模型根据 Issue 内容生成。

评估

技术栈
android, react-native
领域
mobile
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。