Commit 181a6f6
authored
[iOS] Prevent duplicated events in Native gesture handling (#4125)
## Description
I've noticed that when `Native` gesture is not attached to `UIControl`
it sends different events (e.g. events containing `x` and `y`
positions). I've changed that to mimic behavior from #4102
## Test plan
<details>
<summary>Tested on the following example</summary>
```tsx
import { ScrollView, StyleSheet, View } from 'react-native';
import {
GestureDetector,
GestureHandlerRootView,
ScrollView as RNGHScrollView,
Touchable,
useNativeGesture,
} from 'react-native-gesture-handler';
export default function App() {
const g = useNativeGesture({
onBegin: () => {
console.log(Date.now(), 'gesture begin');
},
onActivate: () => {
console.log(Date.now(), 'gesture activate');
},
onUpdate: (e) => {
console.log(Date.now(), 'gesture update', e);
},
onDeactivate: () => {
console.log(Date.now(), 'gesture deactivate');
},
onFinalize: () => {
console.log(Date.now(), 'gesture finalize');
},
shouldCancelWhenOutside: false,
});
return (
<GestureHandlerRootView style={styles.container}>
<Touchable
cancelOnLeave={false}
style={{
width: 150,
height: 45,
backgroundColor: 'crimson',
borderRadius: 8,
}}
/>
<GestureDetector gesture={g}>
<ScrollView style={[styles.scrollView, { backgroundColor: 'green' }]}>
{BOXES.map((color, i) => (
<View key={i} style={[styles.box, { backgroundColor: color }]} />
))}
</ScrollView>
</GestureDetector>
<RNGHScrollView
onBegin={() => {
console.log(Date.now(), 'gesture begin');
}}
onActivate={() => {
console.log(Date.now(), 'gesture activate');
}}
onUpdate={() => {
console.log(Date.now(), 'gesture update');
}}
onDeactivate={() => {
console.log(Date.now(), 'gesture deactivate');
}}
onFinalize={() => {
console.log(Date.now(), 'gesture finalize');
}}
style={[styles.scrollView, { backgroundColor: 'blue' }]}>
{BOXES.map((color, i) => (
<View key={i} style={[styles.box, { backgroundColor: color }]} />
))}
</RNGHScrollView>
</GestureHandlerRootView>
);
}
const BOXES = [
'#ff6b6b',
'#ffd93d',
'#6bcb77',
'#4d96ff',
'#c77dff',
'#ff9f43',
'#ee5a24',
'#0652dd',
'#1289a7',
'#d980fa',
];
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
scrollView: {
width: 200,
maxHeight: 250,
marginVertical: 8,
},
box: {
width: '100%',
height: 60,
marginBottom: 4,
},
});
```
</details>1 parent 5a847d1 commit 181a6f6
3 files changed
Lines changed: 28 additions & 6 deletions
File tree
- packages/react-native-gesture-handler/apple
- Handlers
Lines changed: 18 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
195 | 205 | | |
196 | 206 | | |
197 | | - | |
| 207 | + | |
198 | 208 | | |
199 | 209 | | |
200 | 210 | | |
201 | | - | |
202 | 211 | | |
203 | 212 | | |
204 | 213 | | |
| |||
245 | 254 | | |
246 | 255 | | |
247 | 256 | | |
248 | | - | |
249 | 257 | | |
250 | 258 | | |
251 | 259 | | |
| |||
330 | 338 | | |
331 | 339 | | |
332 | 340 | | |
333 | | - | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
334 | 348 | | |
335 | 349 | | |
336 | 350 | | |
| |||
339 | 353 | | |
340 | 354 | | |
341 | 355 | | |
342 | | - | |
343 | | - | |
344 | 356 | | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| 99 | + | |
99 | 100 | | |
100 | 101 | | |
101 | 102 | | |
| |||
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
307 | 307 | | |
308 | 308 | | |
309 | 309 | | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
310 | 315 | | |
311 | 316 | | |
312 | 317 | | |
| |||
368 | 373 | | |
369 | 374 | | |
370 | 375 | | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
371 | 380 | | |
372 | 381 | | |
373 | 382 | | |
| |||
0 commit comments