react / react/react-native

SectionList ListHeaderComponent gets rerendered when sections data changes

未关闭
#23,400 8 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Bug Component: SectionList Ran Commands
主要语言
C++
星标
127k
派生
25.3k
平均合并
1 天 23 小时
30 天内合并 PR
4

描述

🐛 Bug Report

This is a duplicate of:
https://github.com/facebook/react-native/issues/16824
https://github.com/facebook/react-native/issues/16823
https://github.com/facebook/react-native/issues/14249

But since those 3 were closed and they are missing a reproducible example of the bug I'm reopening.

Description

If one uses a TextInput as a ListHeaderComponent when searching and when the returned sections are empty the TextInput loses focus.

If when searching the sections still have data - then the TextInput in the ListHeaderComponent doesn't lose focus.

To Reproduce

https://snack.expo.io/H12h3BgHV

Expected Behavior

I would expect for the TextInput not to lose focus

Code Example

https://snack.expo.io/H12h3BgHV

Environment

[skip envinfo]
RN 0.58

I've been trying to debug this with @pawelczerepak and what we noticed is that VirtualizedCellWrapper
https://github.com/facebook/react-native/blob/master/Libraries/Lists/VirtualizedList.js#L1759
gets unmounted and mounted when sections is an empty array. And when this happens everything inside of it gets unmounted and mounted again.
@sahrens - any ideas on what might be going on here?

贡献指南

打开贡献指南

从这里开始

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

调研方向

使用 Snack 示例复现焦点丢失问题,然后检查 Libraries/Lists/VirtualizedList.js 第 1759 行附近的 VirtualizedCellWrapper 代码。跟踪 sections 变为空时它为什么会卸载并重新挂载,并验证在 section 数据发生变化时 ListHeaderComponent 中的 TextInput 仍保持焦点。

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

评估

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

把新 issue 发到你的邮箱

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