Commit f176465
authored
[Android] Fix
## Description
Logic behind sending touch events on `android` dispatches events into all gesture handlers registered in the orchestrator. This means that interaction with one `GestureDetector` triggers callbacks on the others. This PR adds check for tracked pointer, so that handlers respond only to those that they are tracking.
Fixes #3543
## Test plan
<details>
<summary>Tested on the following example:</summary>
```jsx
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import {
Gesture,
GestureDetector,
GestureHandlerRootView,
} from 'react-native-gesture-handler';
type BoxProps = {
label: string;
};
function Box({ label }: BoxProps) {
const manual = Gesture.Manual()
.onTouchesDown((e) => {
console.log('down', label, e.handlerTag);
})
.onTouchesUp((e) => {
console.log('up', label, e.handlerTag);
})
.onTouchesCancelled(() => {
console.log('cancelled', label);
});
return (
<GestureDetector gesture={manual}>
<View style={styles.box}>
<Text style={styles.text}>{label}</Text>
</View>
</GestureDetector>
);
}
export default function EmptyExample() {
return (
<GestureHandlerRootView style={styles.container}>
<Box label="1" />
<Box label="2" />
</GestureHandlerRootView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
gap: 10,
},
box: {
width: 100,
height: 100,
backgroundColor: 'red',
alignItems: 'center',
justifyContent: 'center',
},
text: {
color: 'white',
fontSize: 20,
fontWeight: 'bold',
},
});
```
</details>onTouches* callbacks being called for all gestures (#3596)1 parent 3b7a19e commit f176465
2 files changed
Lines changed: 17 additions & 9 deletions
File tree
- packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core
Lines changed: 14 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
206 | | - | |
207 | | - | |
208 | | - | |
| 206 | + | |
| 207 | + | |
209 | 208 | | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
210 | 212 | | |
211 | 213 | | |
212 | 214 | | |
213 | | - | |
214 | | - | |
215 | | - | |
| 215 | + | |
| 216 | + | |
216 | 217 | | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
217 | 221 | | |
218 | 222 | | |
| 223 | + | |
| 224 | + | |
219 | 225 | | |
220 | 226 | | |
221 | 227 | | |
| |||
573 | 579 | | |
574 | 580 | | |
575 | 581 | | |
576 | | - | |
| 582 | + | |
577 | 583 | | |
578 | 584 | | |
579 | 585 | | |
580 | | - | |
| 586 | + | |
581 | 587 | | |
582 | 588 | | |
583 | 589 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
| 252 | + | |
252 | 253 | | |
253 | 254 | | |
254 | 255 | | |
| |||
273 | 274 | | |
274 | 275 | | |
275 | 276 | | |
276 | | - | |
| 277 | + | |
| 278 | + | |
277 | 279 | | |
278 | 280 | | |
279 | 281 | | |
| |||
0 commit comments