AAswordman / AAswordman/Operit
[可滚动列表(LazyColumn/设置页)在点击触发状态更新后滚动位置重置到顶部
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 7.9k
- Forks
- 651
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 70
Description
问题描述
在多个使用可滚动列表的界面中,当用户滚动到列表中部、点击某个条目触发状态更新(重组)后,列表滚动位置会被重置回顶部,需要重新滚动才能回到刚才的位置。
复现路径
稳定复现于以下场景:
- 编辑 System Prompt:滚动到中部,点击文本区域准备编辑 → 页面回顶(光标确实停在点击处,但视图跳回顶部)
- 世界书条目编辑:同上
- ToolPkg 的 Compose DSL
LazyColumn:滚动到中部,点击条目切换状态/编辑 → 回顶
期望行为
状态更新(重组)后,列表应保持当前滚动位置,而不是重置到顶部。
技术分析
在 ToolPkg 的 Compose DSL 侧,LazyColumnProps 仅暴露 content 和 spacing,没有任何滚动状态相关的 API(如 scrollState / rememberLazyListState / initialFirstVisibleItemIndex)。即使为每个 item 设置稳定的 key,重组后滚动位置仍会丢失。
由于系统内置的 Prompt / 世界书设置页也有同样表现,推测根因在宿主的 Compose 渲染层——列表的 LazyListState 可能在每次重组时被重新创建,而非通过 rememberSaveable 持久化。
环境
- Android
- 复现于系统设置页与 ToolPkg Compose DSL 自定义 UI
建议
- 宿主侧:为可滚动列表使用
rememberSaveable { rememberLazyListState() }保持滚动位置 - DSL 侧:为
LazyColumnProps暴露可选的滚动状态保持能力(例如preserveScrollPosition或允许传入 stateKey)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing LazyColumnState creation in the host Compose rendering layer and reviewing LazyColumnProps in the ToolPkg Compose DSL. Reproduce the System Prompt, world-book, and ToolPkg cases, then verify that state updates preserve the current scroll position in each view.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100