PanResponder.create() API either loses state or has stale state
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- C++
- Star
- 127k
- Fork
- 25.3k
- Merge trung bình
- 1 ngày 23 giờ
- Pull request đã merge (30 ngày)
- 4
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với packages/react-native/Libraries/Interaction/PanResponder.js, đặc biệt là trạng thái riêng tư và API PanResponder.create được mô tả trong issue, rồi so sánh chúng với mẫu sử dụng PanResponder đã được tài liệu hóa. Xác định cách các handler có thể nhận các giá trị mới nhất mà không làm mất trạng thái cử chỉ; công việc được xem là hoàn tất khi đã thống nhất được hướng API và hành vi tương ứng cho cả việc duy trì trạng thái lẫn tính cập nhật của handler.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, react-native
- Lĩnh vực
- mobile
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 25/100