Skip to content

Commit 135d24d

Browse files
committed
Update docs
1 parent a753003 commit 135d24d

5 files changed

Lines changed: 60 additions & 12 deletions

File tree

packages/docs-gesture-handler/docs/fundamentals/callbacks-events.mdx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,18 @@ Called each time a pointer tracked by the gesture changes state, typically due t
5555
### onDeactivate
5656

5757
```ts
58-
onDeactivate: (event: GestureEvent<HandlerData>, didSucceed: boolean) => void
58+
onDeactivate: (event: GestureEndEvent<HandlerData>) => void
5959
```
6060

61-
Called when handler stops recognizing gestures, but only if the handler activated. It is called before `onFinalize`. If the handler was interrupted, the `didSucceed` argument is set to `false`. Otherwise it is set to `true`.
61+
Called when handler stops recognizing gestures, but only if the handler activated. It is called before `onFinalize`. The event object contains a `canceled` property — if the handler was interrupted or failed to recognize the gesture, `canceled` is set to `true`. Otherwise it is set to `false`.
6262

6363
### onFinalize
6464

6565
```ts
66-
onFinalize: (event: GestureEvent<HandlerData>, didSucceed: boolean) => void
66+
onFinalize: (event: GestureEndEvent<HandlerData>) => void
6767
```
6868

69-
Called when handler stops recognizing gestures. If the handler managed to activate, the `didSucceed` argument is set to `true` and `onFinalize` will be called right after `onDeactivate`. Otherwise it is set to `false`.
69+
Called when handler stops recognizing gestures. The event object contains a `canceled` property — if the handler failed to activate or was interrupted, `canceled` is set to `true`. If the handler managed to activate and completed successfully, `canceled` is set to `false` and `onFinalize` will be called right after `onDeactivate`.
7070

7171
### onTouchesDown
7272

@@ -107,14 +107,18 @@ Called when there will be no more information about this pointer. It may be call
107107
<CollapsibleCode
108108
label="Show composed types definitions"
109109
expandedLabel="Hide composed types definitions"
110-
lineBounds={[0, 4]}
110+
lineBounds={[0, 8]}
111111
src={`
112112
export type GestureEvent<HandlerData> = {
113113
handlerTag: number;
114114
numberOfPointers: number;
115115
pointerType: PointerType;
116116
} & HandlerData;
117117
118+
export type GestureEndEvent<HandlerData> = {
119+
canceled: boolean;
120+
} & GestureEvent<HandlerData>;
121+
118122
export enum PointerType {
119123
TOUCH,
120124
STYLUS,
@@ -126,6 +130,10 @@ export enum PointerType {
126130

127131
`GestureEvent` contains properties common to all gestures (`handlerTag`, `numberOfPointers`, `pointerType`) along with gesture-specific data defined in each gesture's documentation.
128132

133+
### GestureEndEvent
134+
135+
`GestureEndEvent` extends `GestureEvent` with a `canceled` property. It is used in the [`onDeactivate`](#ondeactivate) and [`onFinalize`](#onfinalize) callbacks. When `canceled` is `true`, the gesture was interrupted or failed to activate. When `false`, the gesture completed successfully.
136+
129137
### TouchEvent
130138

131139
<CollapsibleCode

packages/docs-gesture-handler/docs/gestures/_shared/base-gesture-callbacks.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ Set the callback that is being called when the gesture is recognized by the hand
2424

2525
{
2626
<CodeBlock className="language-ts">
27-
{`onDeactivate: (event: ${props.gesture}HandlerData, didSucceed: boolean) => void`}
27+
{`onDeactivate: (event: ${props.gesture}HandlerData & { canceled: boolean }) => void`}
2828
</CodeBlock>
2929
}
3030

31-
Set the callback that is being called when the gesture that was recognized by the handler finishes. It will be called only if the handler was previously in the active state.
31+
Set the callback that is being called when the gesture that was recognized by the handler finishes. It will be called only if the handler was previously in the active state. The event object contains a `canceled` property — if the gesture was interrupted, `canceled` is set to `true`. Otherwise it is set to `false`.
3232

3333
### onFinalize
3434

3535
{
3636
<CodeBlock className="language-ts">
37-
{`onFinalize: (event: ${props.gesture}HandlerData, didSucceed: boolean) => void`}
37+
{`onFinalize: (event: ${props.gesture}HandlerData & { canceled: boolean }) => void`}
3838
</CodeBlock>
3939
}
4040

41-
Set the callback that is being called when the handler finalizes handling gesture - the gesture was recognized and has finished or it failed to recognize.
41+
Set the callback that is being called when the handler finalizes handling gesture - the gesture was recognized and has finished or it failed to recognize. The event object contains a `canceled` property — if the gesture failed to activate or was interrupted, `canceled` is set to `true`. Otherwise it is set to `false`.
4242

4343
### onTouchesDown
4444

packages/docs-gesture-handler/docs/guides/upgrading-to-3.mdx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,32 @@ code2={
9292
`}
9393
/>
9494

95+
### canceled instead of didSucceed
96+
97+
In RNGH2, `onEnd` and `onFinalize` received a second `success` boolean parameter. In RNGH3, this has been replaced with a `canceled` property on the event object itself. Note that the logic is inverted — `canceled: true` corresponds to the old `success: false`.
98+
99+
<CodeComparison
100+
label1={"RNGH 2"}
101+
label2={"RNGH 3"}
102+
code1={
103+
`const gesture = Gesture.Tap()
104+
.onEnd((event, success) => {
105+
if (success) {
106+
console.log('Gesture succeeded!');
107+
}
108+
});
109+
`}
110+
code2={
111+
`const gesture = useTapGesture({
112+
onDeactivate: (event) => {
113+
if (!event.canceled) {
114+
console.log('Gesture succeeded!');
115+
}
116+
},
117+
});
118+
`}
119+
/>
120+
95121
### onChange
96122

97123
`onChange` callback has been removed, and its functionality has been integrated into `onUpdate`. You can now access `change*` properties in `onUpdate` callback.

packages/docs-gesture-handler/docs/under-the-hood/state.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ States manage the internal recognition process. You can hook into these transiti
1414
| **`UNDETERMINED`** | The default initial state of every handler. ||
1515
| **`BEGAN`** | The handler has started receiving touch data but hasn't yet met the activation criteria. | [`onBegin`](/docs/fundamentals/callbacks-events#onbegin) |
1616
| **`ACTIVE`** | The gesture is recognized and activation criteria are met. | [`onActivate`](/docs/fundamentals/callbacks-events#onactivate) when it first transitions into the `ACTIVE` state. <br /><br /> [`onUpdate`](/docs/fundamentals/callbacks-events#onupdate) when it has new data about the gesture. |
17-
| **`END`** | The user successfully completed the gesture. | [`onDeactivate`](/docs/fundamentals/callbacks-events#ondeactivate) with `didSucceed` parameter set to `true`. <br/><br/> [`onFinalize`](/docs/fundamentals/callbacks-events#onfinalize) with `didSucceed` parameter set to `true`. |
18-
| **`FAILED`** | The handler failed to recognize the gesture. | [`onDeactivate`](/docs/fundamentals/callbacks-events#ondeactivate) if the gesture was in `ACTIVE` state before. `didSucceed` parameter will be set to `false` <br/><br/> [`onFinalize`](/docs/fundamentals/callbacks-events#onfinalize) with `didSucceed` parameter set to `false`. |
19-
| **`CANCELLED`** | The system interrupted the gesture. | [`onDeactivate`](/docs/fundamentals/callbacks-events#ondeactivate) if the gesture was in `ACTIVE` state before. `didSucceed` parameter will be set to `false` <br/><br/> [`onFinalize`](/docs/fundamentals/callbacks-events#onfinalize) with `didSucceed` parameter set to `false`. |
17+
| **`END`** | The user successfully completed the gesture. | [`onDeactivate`](/docs/fundamentals/callbacks-events#ondeactivate) with `event.canceled` set to `false`. <br/><br/> [`onFinalize`](/docs/fundamentals/callbacks-events#onfinalize) with `event.canceled` set to `false`. |
18+
| **`FAILED`** | The handler failed to recognize the gesture. | [`onDeactivate`](/docs/fundamentals/callbacks-events#ondeactivate) if the gesture was in `ACTIVE` state before, with `event.canceled` set to `true`. <br/><br/> [`onFinalize`](/docs/fundamentals/callbacks-events#onfinalize) with `event.canceled` set to `true`. |
19+
| **`CANCELLED`** | The system interrupted the gesture. | [`onDeactivate`](/docs/fundamentals/callbacks-events#ondeactivate) if the gesture was in `ACTIVE` state before, with `event.canceled` set to `true`. <br/><br/> [`onFinalize`](/docs/fundamentals/callbacks-events#onfinalize) with `event.canceled` set to `true`. |

skills/gesture-handler-3-migration/SKILL.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ In Gesture Handler 3 some of the callbacks were renamed, namely:
4040
- `onEnd` -> `onDeactivate`
4141
- `onTouchesCancelled` -> `onTouchesCancel`
4242

43+
The `onDeactivate` and `onFinalize` callbacks no longer receive a second `didSucceed`/`success` boolean parameter. Instead, the event object now contains a `canceled` property. Note that the logic is inverted — `canceled: true` corresponds to the old `success: false`.
44+
45+
```jsx
46+
// Old (RNGH2)
47+
.onEnd((event, success) => {
48+
if (success) { /* gesture succeeded */ }
49+
})
50+
51+
// New (RNGH3)
52+
onDeactivate: (event) => {
53+
if (!event.canceled) { /* gesture succeeded */ }
54+
}
55+
```
56+
4357
In the hooks API `onChange` is no longer available. Instead the `*change*` properties were moved to the event available inside `onUpdate`.
4458

4559
All callbacks of a gesture are now using the same type:

0 commit comments

Comments
 (0)