Skip to content

refactor(motion): one release policy picks the snap point a release lands on - #8565

Closed
cixzhang wants to merge 5 commits into
stack/8386from
feat/resolve-detent
Closed

cixzhang wants to merge 5 commits into
stack/8386from
feat/resolve-detent

Conversation

@cixzhang

@cixzhang cixzhang commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #8386 (BottomSheet on the gesture recognizers). Until that lands, this diff includes it; this pull request's own change is its single commit.

What it does

One internal module with one job: pick the snap point a release lands on. resolveSnapPoint (packages/core/src/motion/resolveSnapPoint.ts) takes plain inputs (ascending snap points, position, velocity, a flick threshold, an optional projection, an optional start and step limit) and returns the snap point's index plus the projected rest position it judged from.

  • A slow release lands on the snap point nearest where it was let go, or where it would coast to with projection.
  • A flick lands at least on the next snap point in its direction.
  • With start, a release moving back toward where the drag began cancels to it (spec:AST-094 FR37).
  • With fromIndex and maxSteps, it stays within that many snap points (a pager's one page per release).

It sits on selectSnapPoint (projection + nearest), which stays the math primitive; both doc comments say so, so nobody adds a second "pick the release target" helper. Names follow the platform glossary (resolveSnapPoint, flickThreshold). It isn't exported from the package or any barrel (resolveSnapPoint.test.ts locks that). It contains no component names.

Adopters

  • BottomSheet: resolveSheetRelease calls it with the sheet's UIKit thresholds (sheet.release.fastSpeed, detentTolerance, projectionSeconds, minProjectionSpeed) instead of its own projection, flick and cancel code. The code moved here unchanged; the sheet's springs and dismiss mapping stay the sheet's.
  • Pager: selectPage moves to motion/selectPage.ts and calls it: no flick, one page per release, and the paging deceleration rate expressed as the seconds it projects (the same projection to floating-point rounding).
  • Interactive-transition driver: its header points release rules at resolveSnapPoint. The driver itself picks no landing; its rules do, and the sheet's rule now goes through this module.
  • Item swipe adopts on refactor(Item): swipe actions run on the interactive-transition driver #8344 once this is in its base (fix-once).
  • Switch is deliberately excluded. Its UISwitch rule flips during the drag by distance from where the finger landed and commits the side shown; it never picks a rest position from a release, so routing it through a detent policy would change its behavior.
  • Two-axis rest points are out of scope.

No behavior change

The existing release tests are the oracle and pass unchanged: BottomSheet's sheetRelease.test.ts (UIKit-measured releases) and useSheetGestures.test.ts, plus projection.test.ts and the paging tests, now in selectPage.test.ts. Across packages/core/src/motion and packages/core/src/BottomSheet, 1,141 tests pass. resolveSnapPoint.test.ts adds direct cases for each rule and the export lock. The real-browser check is the BottomSheet detent and drag specs, which this PR's CI runs because the change touches the BottomSheet folder.

Size (gzip KB, minified)

Method: a fresh packages/core dist at the base (#8386) and at this head; an entry re-exporting the component; esbuild bundle, minify, splitting, ESM, packages external. Desktop is the static-import closure; phone is all chunks.

Component Desktop Phone
BottomSheet 53.32 → 53.42 (+0.10) 53.32 → 53.42 (+0.10)
Popover 36.71 → 36.71 (+0.00) 85.61 → 85.72 (+0.11)
Drawer 25.01 → 25.01 (+0.00) 67.69 → 67.78 (+0.09)
Selector 65.69 → 65.70 (+0.01) 111.29 → 111.40 (+0.11)
DropdownMenu 60.07 → 60.08 (+0.01) 120.27 → 120.40 (+0.13)
DateInput 109.81 → 109.92 (+0.11) 110.00 → 110.11 (+0.11)
Table 70.99 → 70.99 (+0.00) 119.58 → 119.69 (+0.11)

Every component that reaches the sheet gains about 0.1 KB. That's the module's general inputs (optional projection, step limit), which the sheet's inline code didn't need. The pager has no shipped consumer yet.

Testing

  • pnpm vitest run --project ui packages/core/src/motion packages/core/src/BottomSheet: 1,141 pass.
  • tsc and eslint clean.
  • [chore] changeset (internal, no behavior change).

Co-authored with vjeux (the sheet's release code moves here).

resolveDetent (motion/resolveDetent.ts, internal) is the motion foundation's
release policy on selectSnapPoint: a slow release lands on the detent nearest
where it was let go or projects to, a flick at least on the next detent in its
direction, a release moving back toward its start cancels to it, and an
optional step limit keeps it within N detents of where it started.

- BottomSheet's resolveSheetRelease calls it with the sheet's UIKit
  thresholds instead of its own projection, flick and cancel code (moved
  from here unchanged; its release tests are the oracle).
- selectPage moves to motion/selectPage.ts and calls it (one page per
  release, the paging rate as seconds of projection, no flick).
- The interactive driver's header points release rules at it.
Not exported from the package or any barrel; a test locks that.

Co-authored-by: Christopher Chedeau <[email protected]>
@vercel

vercel Bot commented Oct 26, 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 27, 2026 12:43am UTC

Request Review

@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Oct 26, 2026
@astracat-bot

astracat-bot Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 27, 2026, 1:17 AM UTC

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

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

Previews ready: Storybook and Sandbox were built with this PR's docsite. CI evidence will be added when available.

View Storybook for this PR · View Sandbox for this PR

@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 changes for scope only. Against main, this pull request carries the whole unlanded #8386 stack (213 files, 42,582 changed lines), while the release-policy change itself is 10 files and 608 lines. Please land #8386 and its ancestors and rebase, or point the base at #8386's branch, so that the diff is this one commit; on its own, the commit reads as behavior-preserving, with the sheet's and the pager's landings unchanged and the existing release tests passing as they are. One small follow-up: the new guidance in packages/core/src/motion/interactive.ts says every release rule picks its rest position with resolveDetent, but the sheet's mouse path still uses resolveSettleOffset, so please scope that comment to the finger path.

[Automated review]

Comment thread packages/core/src/motion/interactive.ts Outdated
Comment on lines +32 to +34
* A release rule that picks one of a set of rest positions picks it with
* `resolveDetent` (resolveDetent.ts), the motion foundation's release
* policy, rather than with its own nearest/flick logic.

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.

This says every release rule that picks among rest positions uses resolveDetent, but the sheet's own rule still picks a mouse release's detent with resolveSettleOffset (sheetRelease.ts:357-366 calls resolveDefaultRelease, which uses snapOffsets.ts:227-246). Could this be scoped to the finger path, or name the mouse path as the exception, so the next author doesn't read resolveSettleOffset as a violation?

The interactive driver's header said every release rule picks its rest
position with resolveDetent, but the sheet's mouse path still settles with
resolveSettleOffset. It now says a finger path's release rule does, and a
mouse path may keep its own rule.
Platform glossary names, aligned to the merged records: the release policy is
resolveSnapPoint (motion/resolveSnapPoint.ts) over the selectSnapPoint
primitive, its inputs are snap points, and the flick input is flickThreshold.
The back-out cancel stays an input, not an option: a release moving back
toward a given start always cancels to it (spec:AST-094 FR37). No behavior
change; the release tests pass unchanged.
@cixzhang cixzhang changed the title refactor(motion): one release policy picks the detent a release lands on refactor(motion): one release policy picks the snap point a release lands on Oct 26, 2026

@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 changes for scope only: against main, this pull request still carries the whole unlanded #8386 stack (213 files, 42,583 authored lines), while the release-policy change itself is 10 files and 612 lines. Please land #8386 and its ancestors and rebase, or base this pull request on a branch in this repository that holds #8386's head (#8386's own branch is on a fork, so it can't be picked as the base directly), so that the diff is just this change and CI can run on it. On its own, the change reads as behavior-preserving: the sheet's and the pager's landings follow from the same algorithm and thresholds, and the earlier note about the interactive.ts guidance is addressed.

[Automated review]

@cixzhang
cixzhang changed the base branch from main to stack/8386 October 26, 2026 20:18

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

This looks ready: resolveSnapPoint reproduces the sheet's and the pager's landings exactly, and the change stays within the current touch-presentation and release-velocity specs. Because the base is stack/8386, the CI and Lint workflows haven't run on it yet, so please make sure they pass once it targets main. Two optional test tweaks are noted inline: the tolerance case releases past the snap point, so it passes without tolerance, and the barrel loop finds no index file in motion/.

[Automated review]

expect(
resolveSnapPoint({
points: [0, 300, 640],
position: 300.5,

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.

Non-blocking: at 300.5 the release is already past the 300 snap point, so the flick lands on 640 with or without tolerance, and this case still passes when the tolerance is removed. A release just short of the point, such as position: 299.5, lands on 640 with tolerance: 1 and on 300 without, so it would pin the rule.

Comment on lines +180 to +187
const barrels = fs
.readdirSync(here)
.filter(name => /^index\.(ts|tsx|js|mjs)$/.test(name));
for (const barrel of barrels) {
expect(fs.readFileSync(path.join(here, barrel), 'utf8')).not.toMatch(
/resolveSnapPoint/,
);
}

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.

Non-blocking: packages/core/src/motion/ has no index.* file, so barrels is always empty and this loop asserts nothing. The root-index check above already covers the barrels the root star-re-exports, BottomSheet/index.ts among them; either point the loop at the published subpath barrels the root does not star-re-export (such as ./Layer), or drop it and say "package root and exports map" in the title.

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

This looks ready to merge: resolveSnapPoint reproduces BottomSheet's and the pager's landings exactly, and the change stays within the current touch-presentation and release-velocity specs. Because the base is stack/8386, the CI and Lint workflows have not run on it, so please confirm they pass once it targets main. Two optional test tweaks would make resolveSnapPoint.test.ts prove what its titles say: release the tolerance case just short of the snap point (at 299.5 px, say) instead of past it, and point the barrel loop at a barrel that exists or drop it.

[Automated review]

cixzhang added a commit that referenced this pull request Oct 27, 2026
…Point

Where a release lands is decided in one place: motion/resolveSnapPoint.ts.
A slow release lands on the snap point nearest where it would rest; a flick
(flickThreshold or faster) goes at least to the next snap point in its
direction; with start, a release moving back toward it cancels to it
(spec:AST-094 FR37); with fromIndex and maxSteps it moves at most that many
points. selectSnapPoint in projection.ts stays the math primitive, and
paging moves to selectPage.ts on top of resolveSnapPoint. Internal: not
exported from the package (a test locks that). No behavior change.

Split from #8565 so the public drag-to-snap-points API can build on it;
cixzhang added a commit that referenced this pull request Oct 27, 2026
…Point

Where a release lands is decided in one place: motion/resolveSnapPoint.ts.
A slow release lands on the snap point nearest where it would rest; a flick
(flickThreshold or faster) goes at least to the next snap point in its
direction; with start, a release moving back toward it cancels to it
(spec:AST-094 FR37); with fromIndex and maxSteps it moves at most that many
points. selectSnapPoint in projection.ts stays the math primitive, and
paging moves to selectPage.ts on top of resolveSnapPoint. Internal: not
exported from the package (a test locks that). No behavior change.

Split from #8565 so the public drag-to-snap-points API can build on it;
#8565 keeps the bottom sheet's adoption.
@github-actions github-actions Bot removed the needs:design-review Affects visuals — Design should review label Oct 31, 2026
@cixzhang

cixzhang commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

(Posted by Cindy's agent.) Superseded by #8663, which put the one release policy (resolveSnapPoint) on main; the pager and BottomSheet already use it.

@cixzhang cixzhang closed this Nov 9, 2026
@github-actions
github-actions Bot deleted the feat/resolve-detent branch November 10, 2026 06:04

This branch was successfully deployed

1 active deployment
Preview — c7b681f7 Deployed Oct 27, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant