Repository navigation
Commit 6f45895
authored
## Description
`useTapGesture` never sets `shouldCancelWhenOutside`, so a v3 `Tap`
keeps recognizing after the finger leaves the view on Apple and web.
Both older APIs send `true` for `Tap`:
* v1: `src/handlers/TapGestureHandler.ts:94` sets `config: {
shouldCancelWhenOutside: true }`
* v2: `src/handlers/gestures/tapGesture.ts:16` calls
`this.shouldCancelWhenOutside(true)` in the constructor
The docs describe the same contract for the v3 hooks, in
`packages/docs-gesture-handler/docs/gestures/_shared/base-gesture-config.mdx:22`:
> Most handlers' `shouldCancelWhenOutside` property defaults to `false`
except for the [`LongPress`](/docs/gestures/use-long-press-gesture),
[`Tap`](/docs/gestures/use-tap-gesture) and
[`Native`](/docs/gestures/use-native-gesture) (on Android and web),
which default to `true`.
The value has to come from JS, because only Android defaults it to
`true` on its own:
* Android: `TapGestureHandler.kt:33-35` sets it in `init`, and
`resetConfig` restores a `true` `DEFAULT_SHOULD_CANCEL_WHEN_OUTSIDE`
(`TapGestureHandler.kt:193`), shadowing the `false` one in
`GestureHandler.kt:1004`
* Apple: `RNGestureHandler.mm:120` sets `_shouldCancelWhenOutside = NO`
in `resetConfig`, `setConfig` calls `resetConfig` and then only assigns
the property when the key is present (`RNGestureHandler.mm:149-152`),
and `RNTapHandler` does not override it
* Web: `src/web/handlers/GestureHandler.ts:45` initializes
`_shouldCancelWhenOutside = false`, and the web `TapGestureHandler` does
not override it
`useLongPressGesture` already applies its own default through a props
transformer (`useLongPressGesture.ts:21-29`); this applies the `Tap`
default the same way, so an explicitly configured value still wins.
## Test plan
Two tests added to `src/__tests__/api_v3.test.tsx`:
* `useTapGesture()` and `useLongPressGesture()` both end up with
`shouldCancelWhenOutside: true`
* `useTapGesture({ shouldCancelWhenOutside: false })` keeps `false`
The first one fails on `main` with `Expected: true, Received:
undefined`, and passes with the change. I also reverted just the two
source files with the test kept, and confirmed it goes red for that
reason, then restored them.
Commands run in this checkout:
* `yarn workspace react-native-gesture-handler test` -> 19 suites, 161
tests passing (159 before this change)
* `yarn ts-check` from the repository root -> clean
* `yarn workspace react-native-gesture-handler lint-js` -> 0 errors,
prettier clean
Not verified on a device or simulator: the change is confined to the JS
config that the hook hands to the native side, so the check above is the
config assertion rather than an on-device gesture run.
1 parent b6ff243 commit 6f45895
3 files changed
Lines changed: 41 additions & 2 deletions
File tree
- packages/react-native-gesture-handler/src
- __tests__
- v3/hooks/gestures/tap
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
17 | 21 | | |
18 | 22 | | |
19 | 23 | | |
| |||
152 | 156 | | |
153 | 157 | | |
154 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
155 | 178 | | |
156 | 179 | | |
157 | 180 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
94 | 99 | | |
95 | 100 | | |
96 | 101 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
21 | 32 | | |
22 | 33 | | |
23 | 34 | | |
| |||
27 | 38 | | |
28 | 39 | | |
29 | 40 | | |
30 | | - | |
| 41 | + | |
31 | 42 | | |
32 | 43 | | |
33 | 44 | | |
| |||
0 commit comments