react / react/react-native

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

Offen
#39,559 3 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

API: PanResponder Never gets stale
Vorherrschende Sprache
C++
Sterne
127k
Forks
25.3k
Ø Merge
1 T. 23 Std.
Gemergte PRs (30 T.)
4

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit packages/react-native/Libraries/Interaction/PanResponder.js, insbesondere mit dem privaten Zustand und der in der Issue beschriebenen PanResponder.create API, und vergleiche sie mit dem dokumentierten Verwendungsmuster von PanResponder. Ermittle, wie Handler aktuelle Werte erhalten können, ohne den Gestenzustand zu zerstören; als abgeschlossen gilt die Aufgabe, wenn eine abgestimmte API-Richtung und das entsprechende Verhalten sowohl für die Zustandserhaltung als auch für die Aktualität der Handler feststehen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, react-native
Bereich
mobile
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.