Commit 1f723ec
authored
Cancel handlers by
## Description
This is a follow-up PR to #2787 that is meant to fix scrolling of swipeable elements. It overrides `shouldHandlerBeCancelledBy` method so that **_active_** `NativeViewGestureHandler` that is _**not a button**_, will cancel other handler.
Keep in mind that on web, if scroll has already started we cannot cancel it by calling `preventDefault`, hence it makes sense to cancel other handlers in that case (but we may want to limit it just to `Pan`).
Fixes #2617
## Test plan
Tested on
- Swipeable example in our example app
- Transformations example with added text to achieve scrolling
<details>
<summary> Modified code from #2617 </summary>
```jsx
import React from 'react';
import { View, Text } from 'react-native';
import { FlatList, GestureHandlerRootView } from 'react-native-gesture-handler';
import Swipeable from 'react-native-gesture-handler/Swipeable';
export default function Home() {
type ItemProps = {
item: {
text: string;
};
};
const data = Array.from({ length: 50 }, (_, i) => ({
id: i,
text: `Item ${i}`,
}));
const Item = ({ item }: ItemProps) => {
return (
<View style={{ margin: 10 }}>
<Swipeable
renderRightActions={() => (
<View
style={{
justifyContent: 'center',
}}>
<Text style={{ color: 'white', textAlign: 'center' }}>
Delete
</Text>
</View>
)}>
<View
style={{
height: 50,
backgroundColor: 'white',
justifyContent: 'center',
}}>
<Text>{item.text}</Text>
</View>
</Swipeable>
</View>
);
};
return (
<GestureHandlerRootView>
<FlatList
data={data}
keyExtractor={(item) => item.id.toString()}
renderItem={({ item }) => <Item item={item} />}
style={{ maxHeight: 400 }}
/>
</GestureHandlerRootView>
);
}
```
</details>NativeViewGestureHandler (#2788)1 parent b587af3 commit 1f723ec
File tree
2 files changed
+13
-9
lines changed- src/web
- handlers
- tools
2 files changed
+13
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
32 | 31 | | |
33 | 32 | | |
34 | 33 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
| 34 | + | |
40 | 35 | | |
41 | 36 | | |
42 | 37 | | |
| |||
164 | 159 | | |
165 | 160 | | |
166 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
167 | 166 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
| 3 | + | |
2 | 4 | | |
3 | 5 | | |
4 | 6 | | |
| |||
102 | 104 | | |
103 | 105 | | |
104 | 106 | | |
105 | | - | |
| 107 | + | |
106 | 108 | | |
107 | | - | |
108 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
109 | 114 | | |
110 | 115 | | |
111 | 116 | | |
| |||
0 commit comments