v3 `usePanGesture`: `validateOffsetsArray` reads shared values during render (Reanimated warning in `__DEV__`)
维护者通常 3 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 85/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- react, react-native, typescript
调研方向
从 src/v3/hooks/gestures/pan/usePanGesture.ts 开始,重点查看 validateOffsetsArray 及其从 validatePanConfig 发起的调用;追踪 Shared Values 的类型定义,以及现有监听器如何传递它们。根据 issue 中的复现步骤确认开发环境警告,然后为 activeOffsetX 中的 Shared Values 添加或更新针对性测试。并验证普通数值 offset 仍能正确通过验证。
由索引模型根据 Issue 内容生成。
描述
In __DEV__, usePanGesture calls validatePanConfig synchronously while rendering. validateOffsetsArray unpacks the array entries with maybeUnpackValue, which reads .value of a shared value. Reanimated then warns on every render:
[Reanimated] Reading from `value` during component render. Please ensure that you do not access the `value` property or use `get` method of a shared value while React is rendering a component.
Environment: react-native-gesture-handler 3.3.0 (code unchanged in 3.5.1), react-native-reanimated 4.7.1, Expo SDK 58, React Native 0.88.1, iOS 27.
Steps to reproduce:
const reach = useSharedValue(-40);
const pan = usePanGesture({ activeOffsetX: [reach, 20], onUpdate: () => {} });
Render the component in a dev build: the warning appears on every render (the types allow shared values inside these arrays via WithSharedValue).
Root cause: src/v3/hooks/gestures/pan/usePanGesture.ts:46-47 (maybeUnpackValue<number>(offsets[0]), called from validatePanConfig at line 57-60 and from the hook body at line 152).
Fix: validate only plain numbers; shared values are forwarded to the native side by the existing listeners anyway, so they are not validated at render time:
- const offsetStart = maybeUnpackValue<number>(offsets[0]);
- const offsetEnd = maybeUnpackValue<number>(offsets[1]);
-
- if (offsetStart > 0 || offsetEnd < 0) {
+ const [offsetStart, offsetEnd] = offsets;
+
+ if (
+ (typeof offsetStart === 'number' && offsetStart > 0) ||
+ (typeof offsetEnd === 'number' && offsetEnd < 0)
+ ) {
The maybeUnpackValue import (line 11) then becomes unused. Happy to send this as a PR.
- 主要语言
- TypeScript
- 星标
- 6.8k
- 派生
- 1.1k
- 平均合并
- 4 天 4 小时
- 30 天内合并 PR
- 22
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
software-mansion/react-native-gesture-handler 的其他 Issue
-
Missing repro Platform: Android Platform: iOS
难度 5/5 一周以上 新手友好度 39/100
software-mansion/react-native-gesture-handler#4714 · 1 条评论 ·
维护者通常 3 天内回复
-
[Web] A pan that starts on a Pressable presses it when the mouse button is released可能已有人在做 @mokshupadhyay 于 8 天前认领。 未关闭Platform: Web
难度 4/5 3-5 天 新手友好度 57/100
software-mansion/react-native-gesture-handler#4713 ·
维护者通常 3 天内回复
-
[iOS] Button press feedback invisible on quick taps when Reduce Motion is enabled可能已有人在做 @andreialecu 于 13 天前认领。 未关闭Missing info Platform: iOS Platform: MacOS
难度 3/5 1-2 天 新手友好度 45/100
software-mansion/react-native-gesture-handler#4707 · 2 条评论 ·
维护者通常 3 天内回复
-
[Android] Tapping a Text with a `VirtualGestureDetector` inside a `Touchable` presses the `Touchable` instead when the Text overflows its detector可能已有人在做 @huytdps13400 于 3 天前认领。 未关闭Missing info Platform: Android
难度 4/5 3-5 天 新手友好度 22/100
software-mansion/react-native-gesture-handler#4706 · 1 条评论 ·
维护者通常 3 天内回复
-
[Android] Native gesture docs: a wrapped ScrollView lets RNGH Pressable fire onPress after a swipe可能已有人在做 @stussysenik 于 14 天前认领。 未关闭Platform: Android
难度 3/5 1-2 天 新手友好度 55/100
software-mansion/react-native-gesture-handler#4703 ·
维护者通常 3 天内回复
查看 software-mansion/react-native-gesture-handler 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
laststance/design-world#98 ·
维护者通常 1 天内回复
-
approved check:passed streams:add
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
triage: failed
难度 2/5 1-3 小时 新手友好度 68/100
oxc-project/tsrs#1277 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
ardia-browser/ardia#6798 ·
维护者通常 1 天内回复