react / react/react-native

FlatList > Orientation change > Different Item Heights for Portrait and Landscape Do Not Persist Scroll Position Correctly

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

还没有人认领这个 Issue。

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

描述

Description

render items have a different height (landscape = 50 portrait = 200)

When scrolling down a list of flat list items, when the orientation is changed (from portrait to landscape and vise versa), the current scroll position is incorrect.

It seems to retail the current scroll position in pixels and not by the viewable items that were present pre orientation change?

Note that if you're at the top of the list, there is no issue. It's only when you have scrolled down the list.

I have tried capturing the top viewable item on onViewableItemChanged and attempting to use the ref's scrollToIndex, but to no avail.

Steps to reproduce

Install and execute the application
Scroll down the list
Change orientation
The previously viewable items are no longer in view

React Native Version

0.76.5

Affected Platforms

Runtime - Android, Runtime - iOS

Output of npx react-native info
npm verbose cli C:\Program Files\nodejs\node.exe C:\Users\MarkAustin\AppData\Roaming\nvm\v22.12.0\node_modules\npm\bin\npm-cli.js
npm info using npm@10.9.0
npm info using node@v22.12.0
npm verbose title npm exec react-native info
npm verbose argv "exec" "--" "react-native" "info"
npm verbose logfile logs-max:10 dir:d:\workspace\npm-cache\_logs\2024-12-18T15_49_53_732Z-
npm verbose logfile d:\workspace\npm-cache\_logs\2024-12-18T15_49_53_732Z-debug-0.log
info Fetching system and libraries information...
(node:27612) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
System:
  OS: Windows 11 10.0.26100
  CPU: (22) x64 Intel(R) Core(TM) Ultra 7 155H
  Memory: 12.54 GB / 31.70 GB
Binaries:
  Node:
    version: 22.12.0
    path: C:\Program Files\nodejs\node.EXE
  Yarn: Not Found
  npm:
    version: 10.9.0
    path: C:\Program Files\nodejs\npm.CMD
  Watchman: Not Found
SDKs:
  Android SDK: Not Found
  Windows SDK: Not Found
IDEs:
  Android Studio: AI-242.23339.11.2421.12550806
  Visual Studio:
    - 17.12.35506.116 (Visual Studio Enterprise 2022)
Languages:
  Java: 17.0.13
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli":
    installed: 15.0.1
    wanted: 15.0.1
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.76.5
    wanted: 0.76.5
  react-native-windows: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

npm verbose cwd D:\Workspace\rn-replications\flatlist-orientiation\ReproducerApp
npm verbose os Windows_NT 10.0.26100
npm verbose node v22.12.0
npm verbose npm  v10.9.0
npm verbose exit 0
npm info ok
Stacktrace or Logs
N/A
Reproducer

https://github.com/markaustinws/flatlist-orientiation

Screenshots and Videos

flatlist orientation change

贡献指南

打开贡献指南

从这里开始

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

调研方向

首先运行链接的 flatlist-orientiation 复现程序,并观察滚动和改变方向后的 FlatList。将其行为与报告中对 onViewableItemChanged 和 scrollToIndex 的尝试进行比较;当在 Android 和 iOS 上在竖屏与横屏之间切换后,之前可见的项目仍保持在视图中时,即表示完成。

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

评估

技术栈
react-native
领域
mobile
Issue 类型
缺陷
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
需要澄清
新手友好度
28/100

把新 issue 发到你的邮箱

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