Commit 76caf44
authored
Virtual detector native gestures (#3765)
## Description
This PR makes `VirtualDetector` compatible with native gestures. Back in
#3689 I decided to handle `VirtualDetector` compatibility with native
gestures for later, as it is a extremely niche feature and it seemed to
require a lot of work. Turns out it doesn't, beacause we use wrap in
VirtualDetector we can handle them as normal gestures.
## Test plan
Tested on:
<details>
```tsx
import * as React from 'react';
import { StyleSheet, Text, View, ScrollView, Button } from 'react-native';
import {
GestureHandlerRootView,
GestureDetector,
useNative,
useTap,
InterceptingGestureDetector
} from 'react-native-gesture-handler';
export default function App() {
const items = Array.from({ length: 100 }, (_, index) => `Item ${index + 1}`);
const [enabled, setEnabled] = React.useState(true);
const gesture = useNative({
onStart: (e) => {
'worklet';
console.log('onStart');
}
});
const outerGesture = useTap({
onStart: (e) => {
'worklet'
console.log('onOuterStart');
}
});
const SV1 = () => (
<ScrollView style={styles.scrollView1}>
{items.map((item, index) => (
<View key={index} style={styles.item}>
<Text style={styles.text}>{item}</Text>
</View>
))}
</ScrollView>
);
const SV2 = () => (
<ScrollView style={styles.scrollView2}>
{items.map((item, index) => (
<View key={index} style={styles.item}>
<Text style={styles.text}>{item}</Text>
</View>
))}
</ScrollView>
);
return (
<GestureHandlerRootView style={styles.root}>
<View style={styles.buttonContainer}>
<Button
title="Swap the child"
onPress={() => setEnabled(!enabled)}
color="#4a90e2"
/>
</View>
<InterceptingGestureDetector gesture={outerGesture}>
<View style={styles.outerContainer}>
<View style={styles.frame}>
<GestureDetector gesture={gesture}>
{enabled ? <SV1 /> : <SV2 />}
</GestureDetector>
</View>
</View>
</InterceptingGestureDetector>
</GestureHandlerRootView>
);
}
const styles = StyleSheet.create({
scrollView1: {
backgroundColor: 'pink',
marginHorizontal: 20,
},
scrollView2: {
backgroundColor: 'lightblue',
marginHorizontal: 20,
},
item: {
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
padding: 20,
margin: 2,
backgroundColor: 'white',
borderRadius: 10,
},
text: {
fontSize: 20,
color: 'black',
},
root: {
flex: 1,
backgroundColor: '#fafafa',
paddingTop: 60,
alignItems: 'center',
},
buttonContainer: {
marginBottom: 20,
width: '80%',
},
outerContainer: {
padding: 14,
backgroundColor: '#fff',
borderRadius: 18,
borderWidth: 1,
borderColor: '#e0e0e0',
shadowColor: '#000',
shadowOffset: { width: 0, height: 4 },
shadowOpacity: 0.12,
shadowRadius: 8,
elevation: 5,
},
frame: {
borderRadius: 14,
borderWidth: 1,
borderColor: '#d6d6d6',
backgroundColor: '#fdfdfd',
overflow: 'hidden',
},
innerContainer: {
paddingVertical: 24,
paddingHorizontal: 20,
borderRadius: 12,
alignItems: 'center',
justifyContent: 'center',
},
active: {
backgroundColor: '#e9f7ef',
borderColor: '#4caf50',
borderWidth: 1.5,
},
inactive: {
backgroundColor: '#fff8e1',
borderColor: '#ffb300',
borderWidth: 1,
},
});
```
</details>1 parent 8dd560f commit 76caf44
File tree
4 files changed
+60
-37
lines changed- packages/react-native-gesture-handler
- android/src/main/java/com/swmansion/gesturehandler/react
- apple
- src/v3/detectors
- VirtualDetector
4 files changed
+60
-37
lines changedLines changed: 15 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
| 93 | + | |
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
124 | 138 | | |
125 | 139 | | |
126 | 140 | | |
127 | 141 | | |
128 | 142 | | |
129 | | - | |
130 | 143 | | |
131 | 144 | | |
132 | 145 | | |
133 | 146 | | |
134 | 147 | | |
135 | 148 | | |
136 | 149 | | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | 150 | | |
146 | 151 | | |
147 | 152 | | |
| |||
Lines changed: 12 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
| 174 | + | |
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
| |||
236 | 236 | | |
237 | 237 | | |
238 | 238 | | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | 239 | | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | 240 | | |
250 | 241 | | |
251 | 242 | | |
252 | 243 | | |
253 | 244 | | |
254 | 245 | | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
255 | 257 | | |
256 | 258 | | |
257 | 259 | | |
| |||
Lines changed: 10 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
| 56 | + | |
| 57 | + | |
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
| |||
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
112 | 121 | | |
113 | 122 | | |
114 | 123 | | |
| |||
118 | 127 | | |
119 | 128 | | |
120 | 129 | | |
121 | | - | |
122 | 130 | | |
123 | 131 | | |
124 | 132 | | |
| |||
134 | 142 | | |
135 | 143 | | |
136 | 144 | | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | 145 | | |
142 | 146 | | |
143 | 147 | | |
| |||
Lines changed: 23 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | 28 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
40 | | - | |
41 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
42 | 54 | | |
43 | 55 | | |
44 | 56 | | |
| |||
0 commit comments