`@effect/ui-native` (Effect-TS/ui): `kit/Pan` fires stale non-zero `vx`/`vy` on `onEnd` after user pauses still before lifting

未关闭 适合新手
#11,091 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
react-native, typescript
领域
frontend, mobile

调研方向

阅读 packages/ui-native/src/kit/Pan.ts 第 283–314 行附近的代码,以及链接的复现测试 05-pan-stale-velocity-on-end-after-pause/repro.test.ts。追踪移动事件如何更新速度,以及结束事件如何报告速度;复现暂停 500 ms 的情况。完成标准是:暂停后 onEnd 报告的速度接近零,同时在移动后很快松开时仍保留预期的速度。

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

描述

partially generated with help of my ai friend - neon 4.4

Hi effect team,
I was trying out this package and wanted to report some bugs encountered while porting a library to effect native

What version of Effect is running?
  • effect: 4.1.7
  • @effect/ui & @effect/ui-native: Effect-TS/ui main at 77391ee50ae3d3175d670facbf675e9a819ba6a6
  • react-native: 0.88.1
What steps can reproduce the bug?
  1. Clone the minimal reproduction repository:
    git clone https://github.com/cliffordfajardo/effectui-native-error-reproductions.git
    cd effectui-native-error-reproductions
    pnpm install
    pnpm vitest run 05-pan-stale-velocity-on-end-after-pause
    
  2. Attach Pan.on({ axis: "x", onMove, onEnd }) to a draggable view (such as a swipeable row or drawer):
    • topTouchStart at (x: 100, t: 1000)
    • topTouchMove past slop to (x: 120, t: 1016)
    • Fast topTouchMove to (x: 140, t: 1032) (vx = 1.25 px/ms)
    • User holds their finger completely stationary for 500 ms (no further move events)
    • topTouchEnd at (x: 140, t: 1532)

See 05-pan-stale-velocity-on-end-after-pause/repro.test.ts.

What is the expected behavior?

After dragging and then holding still for 500 ms before releasing, onEnd should report near-zero velocity (Math.abs(vx) < 0.05) so snap-threshold and Animation.spring({ velocity }) handoff logic treats the release as a stationary release rather than a high-speed flick.

What do you see instead?

packages/ui-native/src/kit/Pan.ts:283-314 computes g.vx and g.vy exclusively during phase === 1 (topTouchMove) using dt = now - g.t, and on phase === 2 (topTouchEnd, lines 307–314) fires end with the unchanged g.vx and g.vy without checking elapsed time since the last move (t).

As a result, onEnd still receives the stale vx = 1.25 px/ms from 500 ms earlier even though the finger stopped moving half a second before lifting.

Additional information

Possible fix in packages/ui-native/src/kit/Pan.ts: on phase === 2, inspect the elapsed time now - t (using touch.timestamp ?? Date.now()). If the elapsed time since the last move exceeds a stillness window (e.g., > 60–100 ms), zero out g.vx and g.vy (or recompute/decay velocity using the total interval up to release).

主要语言
TypeScript
星标
16.7k
派生
808
平均合并
21 小时 22 分钟
30 天内合并 PR
486

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

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

Effect-TS/effect 的其他 Issue

查看 Effect-TS/effect 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

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