react / react/react-native

PanResponder.create() API either loses state or has stale state

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

还没有人认领这个 Issue。

API: PanResponder Never gets stale
主要语言
C++
星标
127k
派生
25.3k
平均合并
1 天 23 小时
30 天内合并 PR
4

描述

Description

PanResponder has a bunch of private state. This means it's not safe to re-create during a gesture: that state would be lost. This means that it's important to keep a ref to PanResponder which is what the docs seem to suggest.

However, holding a ref to it is bad because all the props and state captured by handlers will be stale. To fix this, you have to either update parts of that ref manually, or to recreate the PanResponder instance (which, as mentioned earlier, will reset its state — which seems bad).

I think this says that PanResponder.create API is not a good API for Hooks and need to be revisited. E.g. maybe it should be a Hook like usePanResponder(config) which takes care of updating the appropriate event handlers as needed — or maybe implemented with useRef inside. The important part is that the handlers should always be fresh (and capture fresh values), while the internal state of the gesture recognizer should never be destroyed.

React Native Version

any version

Output of npx react-native info

irrelevant

Steps to reproduce

irrelevant

Snack, screenshot, or link to a repository

irrelevant

贡献指南

打开贡献指南

从这里开始

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

调研方向

从 packages/react-native/Libraries/Interaction/PanResponder.js 开始,重点查看 issue 中描述的私有状态和 PanResponder.create API,并将其与文档中的 PanResponder 使用模式进行比较。确定如何在不破坏手势状态的情况下让处理器接收最新值;完成条件是就 API 方向达成一致,并确定状态保留和处理器时效性两方面对应的行为。

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

评估

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

把新 issue 发到你的邮箱

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