PanResponder.create() API either loses state or has stale state
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 127k
- Forks
- 25.3k
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 4
Description
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
Contributor guide
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 with packages/react-native/Libraries/Interaction/PanResponder.js, especially the private state and PanResponder.create API described in the issue, and compare it with the documented PanResponder usage pattern. Determine how handlers can receive fresh values without destroying gesture state; done requires an agreed API direction and corresponding behavior for both state retention and handler freshness.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react-native
- Domain
- mobile
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100