Add .onCommit() to the gesture builder
`.onCommit(handler)` is available at every builder stage after the direction, returns the same stage, and accumulates handlers in order. Handlers run once, synchronously at release, when the operation commits and before the settling animation, with the same context `.complete()` receives. A throwing handler is reported without stopping later handlers or the operation. Intended for haptic feedback such as `navigator.vibrate`. Named onCommit rather than then so builder stages never become thenables. The builder now threads one frozen draft through its stages. OriginOperationHandle gains a read-only `intent`, which the recognizer reads right after finish() to know whether the release committed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Faarh2Ts6StJPcz2mRiHiR
This commit is contained in:
@@ -411,6 +411,7 @@ The stages have distinct responsibilities:
|
||||
| `.to.*` | Required movement direction and intent-recognition options |
|
||||
| `.complete(predicate)` | Optional release commit/cancel decision |
|
||||
| `.navigate(factory)` | Required target and retained-history intent |
|
||||
| `.onCommit(handler)` | Optional side effect when a release commits |
|
||||
| `.animate(routine)` | Required source/target/frame choreography |
|
||||
|
||||
The builder is persistent and immutable. Reusing an earlier stage cannot
|
||||
@@ -432,6 +433,27 @@ velocity, directed pixel distance, cross-axis distance, duration, pointer-up
|
||||
event, host, bounds, and start/current points. Completion predicates are
|
||||
synchronous because they select operation intent at release.
|
||||
|
||||
`.onCommit(handler)` is available at every stage after `.to.*`, returns the
|
||||
same stage, and may be called more than once; handlers run in order. A handler
|
||||
runs once, synchronously at release, after the operation commits and before
|
||||
the settling animation, and receives the same context as `.complete()`. It
|
||||
never runs for a cancelled release. A throwing handler is reported as an
|
||||
uncaught error without stopping later handlers or the operation. It is the
|
||||
place for haptic feedback:
|
||||
|
||||
```ts
|
||||
const openProfile = gesture.to
|
||||
.left()
|
||||
.navigate(() => forward(originView(ProfileView)))
|
||||
.onCommit(() => navigator.vibrate?.(10))
|
||||
.animate(slideLeft);
|
||||
```
|
||||
|
||||
`navigator.vibrate` is unavailable in iOS Safari; Capacitor apps can call
|
||||
`Haptics.impact()` from `@capacitor/haptics` instead. The method is named
|
||||
`onCommit` rather than `then` so builder stages never become promise-like
|
||||
"thenables" when awaited or returned from an async function.
|
||||
|
||||
### `useOriginGesture(definition)`
|
||||
|
||||
Creates one primary-pointer, single-axis recognizer owned by the component that
|
||||
@@ -640,6 +662,9 @@ can immediately begin its own outgoing operation, enabling X → Y → Z chains.
|
||||
|
||||
### `OriginOperationHandle`
|
||||
|
||||
`intent` reports the selected outcome (`undecided`, `commit`, or `cancel`). It
|
||||
changes synchronously when `finish()` or `cancel()` is called.
|
||||
|
||||
| Member | Description |
|
||||
| ----------------------------- | --------------------------------------------------- |
|
||||
| `id` | Unique operation ID |
|
||||
|
||||
Reference in New Issue
Block a user