Commit d76522f
authored
[Web] Gesture relations (#3713)
## Description
This PR adds a function in web module to configure gesture relations via
hooks from #3693.
## Test plan
```ts
import * as React from 'react';
import { Animated, Button, useAnimatedValue } from 'react-native';
import {
GestureHandlerRootView,
NativeDetector,
useSimultaneous,
useGesture,
useExclusive,
useRace,
SingleGestureName,
} from 'react-native-gesture-handler';
export default function App() {
const [visible, setVisible] = React.useState(true);
const av = React.useRef(new Animated.Value(0)).current
const event = Animated.event(
[{ nativeEvent: { handlerData: { translationX: av } } }],
{
useNativeDriver: true,
}
);
const tap1 = useGesture(SingleGestureName.Tap, {
onEnd: () => {
// 'worklet';
console.log('Tap 1');
},
numberOfTaps: 1,
disableReanimated: true,
});
const tap2 = useGesture(SingleGestureName.Tap, {
onEnd: () => {
// 'worklet';
console.log('Tap 2');
},
numberOfTaps: 2,
disableReanimated: true,
blocksExternalGesture: tap1,
});
// const tap1 = useGesture('TapGestureHandler', {
// onEnd: () => {
// 'worklet';
// console.log('Tap 1');
// },
// numberOfTaps: 1,
// // disableReanimated: true,
// requireExternalGestureToFail: tap2,
// });
const pan1 = useGesture(SingleGestureName.Pan, {
// onUpdate: event,
onUpdate: (e) => {
'worklet';
console.log('Pan 1');
},
// disableReanimated: true,
});
const pan2 = useGesture(SingleGestureName.Pan, {
onUpdate: (e) => {
'worklet';
console.log('Pan 2');
},
simultaneousWithExternalGesture: pan1,
// requireExternalGestureToFail: pan1,
// blocksExternalGesture: pan1,
// disableReanimated: true,
});
// const composedGesture = useSimultaneous(pan1, pan2);
// const composedGesture = useExclusive(tap2, tap1);
// const composedGesture = useExclusive(pan2, pan1); // For Animated.Event
// const composedGesture = useExclusive(pan1, pan2); // For Animated.Event
// const composedGesture = useRace(pan1, pan2);
// const composedGesture = useRace(pan2, pan1);
// const composedGesture = useExclusive(tap1, useSimultaneous(pan1, pan2));
return (
<GestureHandlerRootView
style={{ flex: 1, backgroundColor: 'white', paddingTop: 8 }}>
<Button
title="Toggle visibility"
onPress={() => {
setVisible(!visible);
}}
/>
{visible && (
<NativeDetector gesture={pan1}>
<Animated.View
style={[
{
width: 150,
height: 150,
backgroundColor: 'blue',
opacity: 0.5,
borderWidth: 10,
borderColor: 'green',
marginTop: 20,
marginLeft: 40,
display: 'flex',
alignItems: 'center',
justifyContent: 'space-around',
},
{ transform: [{ translateX: av }] },
]}>
<NativeDetector gesture={pan2}>
<Animated.View
style={{ width: 100, height: 100, backgroundColor: 'green' }}
/>
</NativeDetector>
</Animated.View>
</NativeDetector>
)}
</GestureHandlerRootView>
);
}
```1 parent 48dfbf2 commit d76522f
File tree
3 files changed
+34
-30
lines changed- packages/react-native-gesture-handler/src
- web
- handlers
- tools
3 files changed
+34
-30
lines changedLines changed: 7 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | 41 | | |
45 | 42 | | |
46 | 43 | | |
| |||
75 | 72 | | |
76 | 73 | | |
77 | 74 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | 75 | | |
84 | 76 | | |
85 | 77 | | |
| |||
95 | 87 | | |
96 | 88 | | |
97 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
98 | 96 | | |
99 | 97 | | |
100 | 98 | | |
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
764 | 764 | | |
765 | 765 | | |
766 | 766 | | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
767 | 771 | | |
768 | 772 | | |
769 | 773 | | |
| |||
Lines changed: 23 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
15 | 19 | | |
16 | 20 | | |
17 | 21 | | |
18 | 22 | | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
46 | 48 | | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
53 | 55 | | |
54 | 56 | | |
55 | 57 | | |
| |||
0 commit comments