Repository navigation
fix(core): a BottomSheet release settles where it would coast to - #7170
Conversation
…render useSheetGestures held the live drag offset in React state, so every pointer or touch sample re-rendered the panel before the transform reached the element: one commit per input sample (49 commits for a 24-sample drag in Chromium), the sheet following the finger at the main thread's cadence rather than the input's, and visibly behind it on a busy page. The move handler now writes the compositor transform straight to the sheet element and renders nothing; the live offset is readable through activeOffsetRef. State changes when a drag begins, when the sheet first travels (one change, for the host's keyboard dismissal), when the layout split crosses the base detent (the host renders the new height), and when the drag ends. The panel owns the element's transform outside a drag and writes the resting value after each commit instead of rendering it through the style prop, so React, which never saw the live writes, cannot skip a value it believes unchanged: the settle and the dismissal animate from wherever the finger left the sheet, in the same style update that restores the transition.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
There was a problem hiding this comment.
Requesting one change before approval.
A throw that starts after a pause on the handle is misread: the release-speed window keeps the pointer-down sample (it is only pruned once the second sample is 100ms old), so grab -> rest -> flick reads its speed averaged since touch-down and the sheet springs back instead of dismissing. For example, down, a 250ms still hold, then 60px in 50ms settles rather than closing, where the previous last-two-samples flick dismissed. Dropping or resetting samples that fall outside the 100ms window (including the seeded touch-down sample after a gap) plus a hold-then-throw regression test would close this.
Everything else checks out: the full BottomSheet suite (237 tests), lint, and typecheck pass; in a real-browser drag the sheettracks the finger at 4 React commits for 24 samples (29 before) with identical resting frames before and after; purpose gating and the direction clamp are unchanged, and there is no public API change.
[Automated review]
PR Analysis Report📚 Storybook Preview🧪 Sandbox PreviewNo new or modified components detected. Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Visual Regression24 of 442 shot(s) changed. A change here is a question, not a failure: check whether the after is the
and 4 more. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
Where a drag ends was judged by the finger's last position, with one exception: a flick, defined as the last two samples moving faster than 1.2px/ms over at least 48px, dismissed (or expanded) outright. Everything under that bar snapped by position alone, so a medium throw released short of the dismiss line sprang back, a gentle throw toward the next detent returned to the one it left, one slow sample before the lift cancelled a real throw, and a finger that paused before lifting still carried the speed of its last two samples into the release. The release is now judged where the sheet would come to rest: the release position plus the distance a surface moving at the finger's speed travels while it decelerates at UIKit's normal scroll rate (0.998 per ms), the rule a thrown scroll view settles by. Past the dismiss line it dismisses; otherwise it settles on the detent nearest that point, in the drag's direction. The speed is read over the finger's last 100ms of samples, and a lift more than 100ms after the last move releases no speed at all. A gesture under 48px of travel projects nothing, as before.
72d5921 to
374752a
Compare
|
Addressed: samples older than the window are dropped while a partner remains, and a lone partner older than the window reads the move as if it took the window, so grab, rest, flick reads the flick. Two cases added ( |
There was a problem hiding this comment.
Looks good to approve — thanks for the follow-up fix.
The release now settles where the sheet would coast to, drags track the finger without a render per sample, and a throw that begins after holding the handle is read at its own speed. I verified the full BottomSheet suite (239 tests, including the new hold-then-throw cases), lint, and typecheck, and re-ran the browser drag: 4 React commits for 24 moves (30 before) with identical open/settled frames.
No public API, default, or purpose-gating change. The remaining device-feel tuning of the deceleration constant is a follow-up tuning question, not a blocker.
[Automated review]
Stacked on #7169 (its first commit); only
72d5921is this change.User impact
Anyone releasing a
BottomSheetdrag on a touch screen. A medium throw released short of the dismiss line sprang back instead of closing; a gentle throw toward the next detent returned to the one it left; one slow sample before the lift cancelled a real throw; and a finger that paused before lifting still carried the speed of its last two samples into the release, so a careful placement could close the sheet. With the change the sheet settles where it would coast to at the finger's speed, the way a thrown scroll view does.Problem and solution fit
Why it occurs: the release was judged by the finger's last position, with one exception: a flick, defined as the last two samples moving faster than 1.2px/ms over at least 48px, dismissed or expanded outright. Everything under that bar was placed by position alone, and the two-sample speed never decayed.
Why it harms the task: closing and placing are the sheet's whole gesture vocabulary, and the bar sits above the speed most people throw at, so the sheet reads a throw as a drag and a pause as a throw.
Why it matters: the mismatch is felt on every release, on the devices sheets exist for.
The fix judges the release at its projected rest: the release position plus the distance a surface moving at the finger's speed travels while decelerating at UIKit's normal scroll rate (0.998 per ms). Past the dismiss line it dismisses; otherwise it settles on the detent nearest that point, in the drag's direction. The speed is read over the finger's last 100ms of samples; a lift more than 100ms after the last move releases no speed. A gesture under 48px projects nothing, as before.
Expected behavior and authority
The hook's own contract: "DRAG places, SWIPE closes", a slow drag settling to the nearest detent and a throw closing. No current record fixes the threshold or the projection; this keeps the contract's two outcomes and replaces the two-sample threshold that decided between them.
canDismissand the direction clamp (never back past the starting detent) are unchanged.Smallest restoration
The projection, the sampled speed, and the rest rule inside
settleFromDrag/endDrag, in place of the flick branches. No API, visual, default, or layout change; the release animation itself (a fixed-duration transition) is separable and not touched here.Evidence
does not flick-dismiss on a fast but short nudgestill holds (nothing is projected under 48px of travel).BottomSheet.test.tsx's flick-dismiss and slow-drag cases anda downward drag from a middle detent never snaps back up past it.useSheetGestures.test.ts>release projection(5 cases, all red on the base).Scope
Testing
Real browser: not yet; the decision runs on the same samples the existing paths deliver. A device pass on the throw speeds people actually use is the open question for the owner, and the one constant to tune is the deceleration rate.