Skip to content

fix(core): a BottomSheet release settles where it would coast to - #7170

Merged
imdreamrunner merged 2 commits into
meta:mainfrom
vjeux:sheet-projected-release
Oct 8, 2026
Merged

imdreamrunner merged 2 commits into
meta:mainfrom
vjeux:sheet-projected-release

Conversation

@vjeux

@vjeux vjeux commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Stacked on #7169 (its first commit); only 72d5921 is this change.

User impact

Anyone releasing a BottomSheet drag 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. canDismiss and 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

  • Reproduction before the change: the five new cases fail on the base: a 1px/ms throw released at 150px of a 280px line springs back; a 0.3px/ms throw of 60px returns to the top instead of the 200px detent; a 3px/ms throw followed by one 2px sample springs back; a 3px/ms move followed by 380ms of rest dismisses on lift.
  • Result after the change: each settles as named; does not flick-dismiss on a fast but short nudge still holds (nothing is projected under 48px of travel).
  • Representative unchanged path: all 237 BottomSheet tests pass, including BottomSheet.test.tsx's flick-dismiss and slow-drag cases and a downward drag from a middle detent never snaps back up past it.
  • Regression test or other mutation-sensitive proof: useSheetGestures.test.ts > release projection (5 cases, all red on the base).

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Testing

pnpm vitest run packages/core/src/BottomSheet
 Test Files  7 passed (7)
      Tests  237 passed (237)
pnpm exec eslint packages/core/src/BottomSheet/useSheetGestures.ts packages/core/src/BottomSheet/useSheetGestures.test.ts   # clean
pnpm --filter @astryxdesign/core exec tsc --noEmit   # clean

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.

…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.
@vercel

vercel Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Oct 8, 2026 1:07pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 8, 2026
@astracat-bot

astracat-bot Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 8, 2026, 1:18 PM UTC

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.9KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

24 of 442 shot(s) changed.

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
Selector Indicator Space Bottom Sheet Narrow End RTL neutral light 754,077
Selector Indicator Space Bottom Sheet Wide Start neutral light 740,188
Chat Full AI Chat probe light 155,733
Chat Full AI Chat probe dark 155,005
Chat Default neutral dark 33,205
Chat Default neutral light 32,876
Chat Empty State probe light 23,531
Chat Empty State probe dark 22,622
ChatAutoScroll Scroll Behavior Comparison neutral dark 15,378
ChatAutoScroll Scroll Behavior Comparison neutral light 14,107
Chat With Attachments probe light 13,229
Chat With Attachments probe dark 11,065
TableRowExpansion Detail Panel neutral dark 5,129
TableRowExpansion Detail Panel neutral light 4,050
SideNav Resizable in AppShell probe dark 3,208
SideNav Resizable in AppShell probe light 3,208
TableGroupedRows Default neutral light 2,133
TableGroupedRows Default neutral dark 2,116
Markdown Default probe dark 897
Markdown Default probe light 897

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.
@vjeux
vjeux force-pushed the sheet-projected-release branch from 72d5921 to 374752a Compare October 8, 2026 12:59
@vjeux

vjeux commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

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 (reads a throw that begins after a hold at its own speed, reads a single move after a hold as a move), both red on the first revision.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

@imdreamrunner
imdreamrunner merged commit 9613feb into meta:main Oct 8, 2026
43 checks passed
@vjeux
vjeux deleted the sheet-projected-release branch October 8, 2026 20:05

This branch was successfully deployed

1 active deployment
Preview — 374752ad Deployed Oct 8, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants