Commit e93030d
authored
fix relations (#3722)
## Description
After
#3715
v3 api relations did not work. This PR fixes this issue, now relations
work in both APIs.
## Test plan
<details>
<summary>old api</summary>
```ts
import React from 'react';
import { View, StyleSheet } from 'react-native';
import {
GestureDetector,
Gesture,
GestureHandlerRootView,
} from 'react-native-gesture-handler';
export default function Example() {
const innerTap = Gesture.Tap()
.onStart(() => {
console.log('inner tap');
});
const outerTap = Gesture.Tap()
.onStart(() => {
console.log('outer tap');
})
.simultaneousWithExternalGesture(innerTap);
return (
<GestureHandlerRootView style={styles.container}>
<GestureDetector gesture={outerTap}>
<View style={styles.outer}>
<GestureDetector gesture={innerTap}>
<View style={styles.inner} />
</GestureDetector>
</View>
</GestureDetector>
</GestureHandlerRootView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
outer: {
width: 250,
height: 250,
backgroundColor: 'lightblue',
},
inner: {
width: 100,
height: 100,
backgroundColor: 'blue',
alignSelf: 'center',
},
});
```
</details>
<details>
<summary>new api</summary>
```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,
});
// 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={composedGesture}>
<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 }] },
]}>
</Animated.View>
</NativeDetector>
)}
</GestureHandlerRootView>
);
}
```
</details>1 parent 4790449 commit e93030d
8 files changed
Lines changed: 27 additions & 25 deletions
File tree
- packages/react-native-gesture-handler
- android/src/main/java/com/swmansion/gesturehandler/react
- apple
- src
- handlers
- gestures/GestureDetector
- v3/NativeDetector
- web/handlers
Lines changed: 0 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | 101 | | |
107 | 102 | | |
108 | 103 | | |
| |||
Lines changed: 0 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | 185 | | |
190 | 186 | | |
191 | 187 | | |
| |||
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
164 | | - | |
165 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
166 | 167 | | |
167 | 168 | | |
168 | 169 | | |
| |||
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
405 | 405 | | |
406 | 406 | | |
407 | 407 | | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
408 | 418 | | |
409 | 419 | | |
410 | 420 | | |
| |||
Lines changed: 6 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
| |||
Lines changed: 6 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| 149 | + | |
| 150 | + | |
149 | 151 | | |
Lines changed: 0 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
764 | 764 | | |
765 | 765 | | |
766 | 766 | | |
767 | | - | |
768 | | - | |
769 | | - | |
770 | | - | |
771 | 767 | | |
772 | 768 | | |
773 | 769 | | |
| |||
0 commit comments