Commit a116ba8
authored
[Web] Don't cancel buttons when pointer moves inside (#4100)
## Description
Prevents the buttons from being canceled when the pointer is moved
inside the button.
Note that this only works with a mouse, since the browser will cancel
any events with no `touchAction` during any drag gesture.
## Test plan
|Before|After|
|-|-|
|<video
src="https://github.com/user-attachments/assets/08b342f8-24cc-43e9-a240-844641f97552"
/>|<video
src="https://github.com/user-attachments/assets/5cdc15bf-2518-4602-a180-ffd4ae48745e"
/>|
<details>
<summary>Expand</summary>
```jsx
import React, { useState } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { Touchable } from 'react-native-gesture-handler';
export default function EmptyExample() {
const [isActive, setIsActive] = useState(false);
return (
<View style={styles.container}>
<Touchable
style={[styles.button, isActive && styles.buttonActive]}
onPress={() => console.log('pressed')}
onPressIn={() => setIsActive(true)}
onPressOut={() => setIsActive(false)}
activeScale={1.2}>
<Text style={styles.label}>{isActive ? 'Highlighted' : 'Press me'}</Text>
</Touchable>
<Text style={styles.hint}>
Press the button, then slowly drag your pointer away from it.
</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
padding: 24,
gap: 24,
},
button: {
backgroundColor: '#ddd',
paddingHorizontal: 32,
paddingVertical: 16,
borderRadius: 8,
},
buttonActive: {
backgroundColor: '#f97316',
},
label: {
fontSize: 20,
fontWeight: '600',
},
hint: {
textAlign: 'center',
opacity: 0.6,
fontSize: 14,
},
});
```
</details>1 parent 2154bfd commit a116ba8
2 files changed
Lines changed: 18 additions & 6 deletions
File tree
- packages/react-native-gesture-handler/src/web
- handlers
- tools
Lines changed: 6 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| |||
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
165 | 177 | | |
166 | 178 | | |
167 | 179 | | |
| |||
0 commit comments