Commit c8d66b4
authored
[Web] Make
## Description
Currently `getEffectiveBoundingRect` takes bounding box either from
view, or children if element has `display: contents;`. However, in case
of nested detectors this brakes, as can be seen when running the example
code below.
This PR makes `getEffectiveBoundingRect` recursive, so it will not stop
on the first layer of children.
## Test plan
<details>
<summary>Tested on the following code:</summary>
```tsx
import React, { useState } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import {
GestureDetector,
useHoverGesture,
useNativeGesture,
} from 'react-native-gesture-handler';
// Web-only repro for the getEffectiveBoundingRect fix.
//
// The OUTER hover gesture has a `hitSlop`, which makes its handler run
// checkHitSlop() → measureView() → getEffectiveBoundingRect() on the detector's
// `display:contents` host. The INNER GestureDetector nests a SECOND
// `display:contents` host between that host and the real box (the same shape as
// a hover detector wrapping a Touchable). Before the fix, the outer host's only
// child was itself `display:contents`, so its measured rect collapsed to 0×0 at
// the origin and checkHitSlop rejected every real pointer — hover never fired.
// After the fix, getEffectiveBoundingRect recurses through the inner
// `display:contents` child to the real box, so hover activates normally.
export default function EmptyExample() {
const [hovered, setHovered] = useState(false);
const hover = useHoverGesture({
manualActivation: true,
disableReanimated: true,
hitSlop: { top: 10, bottom: 10, left: 10, right: 10 },
onBegin: () => setHovered(true),
onFinalize: () => setHovered(false),
});
// Any inner gesture works — it exists only to nest a second detector host.
const inner = useNativeGesture({});
return (
<View style={styles.container}>
<GestureDetector gesture={hover}>
<GestureDetector gesture={inner}>
<View style={[styles.box, hovered && styles.boxHovered]}>
<Text style={styles.label}>
{hovered ? 'hovered ✅' : 'hover me (web)'}
</Text>
</View>
</GestureDetector>
</GestureDetector>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
box: {
width: 220,
height: 130,
borderRadius: 16,
backgroundColor: '#a78bfa',
alignItems: 'center',
justifyContent: 'center',
},
boxHovered: {
backgroundColor: '#34d399',
},
label: { fontSize: 18, fontWeight: '700', color: '#1a1a2e' },
});
```
</details>getEffectiveBoundingRect recursive (#4303)1 parent 8bfaefa commit c8d66b4
2 files changed
Lines changed: 36 additions & 15 deletions
Lines changed: 6 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
141 | 143 | | |
142 | 144 | | |
143 | 145 | | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
| |||
345 | 345 | | |
346 | 346 | | |
347 | 347 | | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
| 348 | + | |
353 | 349 | | |
354 | 350 | | |
355 | 351 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
5 | 22 | | |
6 | | - | |
| 23 | + | |
| 24 | + | |
7 | 25 | | |
8 | | - | |
| 26 | + | |
9 | 27 | | |
10 | 28 | | |
11 | 29 | | |
12 | 30 | | |
13 | 31 | | |
14 | 32 | | |
15 | 33 | | |
16 | | - | |
| 34 | + | |
17 | 35 | | |
18 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
19 | 42 | | |
20 | 43 | | |
21 | 44 | | |
22 | 45 | | |
23 | 46 | | |
24 | 47 | | |
25 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
26 | 51 | | |
27 | 52 | | |
28 | 53 | | |
| |||
0 commit comments