Commit 6599d06
authored
## Description
Following #3638 this PR brings support for `NativeViewGestureHandler`
into `NativeDetector` for web. It does so, by attaching handler into
child instead of detector.
## Test plan
Tested on the following code
```ts
import * as React from 'react';
import { StyleSheet, Text, View, ScrollView, Button } from 'react-native';
import {
GestureHandlerRootView,
NativeDetector,
useGesture,
} from 'react-native-gesture-handler';
export default function App() {
const items = Array.from({ length: 5 }, (_, index) => `Item ${index + 1}`);
const [enabled, setEnabled] = React.useState(true);
const gesture = useGesture('NativeViewGestureHandler', {
onBegin: (e) => {
console.log('onBegin', e);
},
onStart: (e) => {
console.log('onStart', e);
}
});
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={{ flex: 1, backgroundColor: 'white', paddingTop: 8 }}>
<Button
title="Swap the child"
onPress={() => {
setEnabled(!enabled);
}}
/>
<NativeDetector gesture={gesture}>
{enabled ? <SV1 /> : <SV2 />}
</NativeDetector >
</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',
},
});
```
1 parent 02e1317 commit 6599d06
4 files changed
Lines changed: 47 additions & 11 deletions
File tree
- packages/react-native-gesture-handler/src
- v3
- web/handlers
Lines changed: 38 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
| 1 | + | |
3 | 2 | | |
4 | 3 | | |
5 | 4 | | |
| 5 | + | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | | - | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| 25 | + | |
| 26 | + | |
23 | 27 | | |
24 | 28 | | |
25 | 29 | | |
| |||
33 | 37 | | |
34 | 38 | | |
35 | 39 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
42 | 65 | | |
43 | 66 | | |
44 | 67 | | |
45 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
46 | 73 | | |
47 | 74 | | |
48 | | - | |
| 75 | + | |
49 | 76 | | |
50 | 77 | | |
51 | 78 | | |
| |||
54 | 81 | | |
55 | 82 | | |
56 | 83 | | |
57 | | - | |
| 84 | + | |
58 | 85 | | |
59 | 86 | | |
60 | 87 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
275 | 275 | | |
276 | 276 | | |
277 | 277 | | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
278 | 282 | | |
279 | 283 | | |
280 | 284 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
173 | 177 | | |
174 | 178 | | |
175 | 179 | | |
| |||
0 commit comments