LongPress not working on web
See original GitHub issueDescription
Not all LongPress callbacks are being called on web.
Platforms
- iOS
- Android
- Web
Screenshots
Steps To Reproduce
Run the code below and press the red circle.
Expected behavior
For all these callbacks to be called:
onTouchesDown
onBegin
onStrart
onTouchesUp
onEnd
onFinalize
Actual behavior
Only these callbacks are called:
onEnd
onFinalize
Snack or minimal code example
import { Platform, StyleSheet, Text } from 'react-native'
import {
Gesture,
GestureDetector,
GestureHandlerRootView,
} from 'react-native-gesture-handler'
import Animated, {
useAnimatedStyle,
useSharedValue,
} from 'react-native-reanimated'
export default function App() {
const isPressed = useSharedValue(false)
const onTouchesDownWasCalled = useSharedValue(false)
const onBeginWasCalled = useSharedValue(false)
const onStartWasCalled = useSharedValue(false)
const onTouchesUpWasCalled = useSharedValue(false)
const onEndWasCalled = useSharedValue(false)
const onFinalizeWasCalled = useSharedValue(false)
const longPressGesture = Gesture.LongPress()
.onTouchesDown(() => {
isPressed.value = true
onTouchesDownWasCalled.value = true
onBeginWasCalled.value = false
onStartWasCalled.value = false
onTouchesUpWasCalled.value = false
onEndWasCalled.value = false
onFinalizeWasCalled.value = false
})
.onBegin(() => {
onBeginWasCalled.value = true
})
.onStart(() => {
onStartWasCalled.value = true
})
.onTouchesUp(() => {
onTouchesUpWasCalled.value = true
})
.onEnd(() => {
onEndWasCalled.value = true
})
.onFinalize(() => {
isPressed.value = false
onFinalizeWasCalled.value = true
})
const onTouchesDownStyles = useAnimatedStyle(() => ({
opacity: onTouchesDownWasCalled.value ? 1 : 0,
}))
const onBeginStyles = useAnimatedStyle(() => ({
opacity: onBeginWasCalled.value ? 1 : 0,
}))
const onStartStyles = useAnimatedStyle(() => ({
opacity: onStartWasCalled.value ? 1 : 0,
}))
const onTouchesUpStyles = useAnimatedStyle(() => ({
opacity: onTouchesUpWasCalled.value ? 1 : 0,
}))
const onEndStyles = useAnimatedStyle(() => ({
opacity: onEndWasCalled.value ? 1 : 0,
}))
const onFinalizeStyles = useAnimatedStyle(() => ({
opacity: onFinalizeWasCalled.value ? 1 : 0,
}))
const ballAnimatedStyles = useAnimatedStyle(() => ({
backgroundColor: isPressed.value ? 'yellow' : 'red',
}))
return (
<GestureHandlerRootView style={styles.container}>
<Text style={styles.text}>
{Platform.OS === 'web' ? 'Web Version' : 'Native Version'}
</Text>
<Animated.View style={onTouchesDownStyles}>
<Text style={styles.text}>`onTouchesDown()` was called.</Text>
</Animated.View>
<Animated.View style={onBeginStyles}>
<Text style={styles.text}>`onBegin()` was called.</Text>
</Animated.View>
<Animated.View style={onStartStyles}>
<Text style={styles.text}>`onStart()` was called.</Text>
</Animated.View>
<Animated.View style={onTouchesUpStyles}>
<Text style={styles.text}>`onTouchesUp()` was called.</Text>
</Animated.View>
<Animated.View style={onEndStyles}>
<Text style={styles.text}>`onEnd()` was called.</Text>
</Animated.View>
<Animated.View style={onFinalizeStyles}>
<Text style={styles.text}>`onFinalize()` was called.</Text>
</Animated.View>
<GestureDetector gesture={longPressGesture}>
<Animated.View style={[styles.ball, ballAnimatedStyles]} />
</GestureDetector>
</GestureHandlerRootView>
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
text: {
paddingBottom: 16,
fontSize: 16,
},
ball: {
width: 128,
height: 128,
borderRadius: 64,
},
})
Package versions
- React: 17.0.1
- React Native: 0.64.3
- React Native Gesture Handler: 2.2.1
- React Native Reanimated: 2.3.3
Issue Analytics
- State:
- Created a year ago
- Comments:11 (4 by maintainers)
Top Results From Across the Web
Long Press in JavaScript? - jquery - Stack Overflow
Any long press event must address multiple issues which this answer ignores. 1) Distinguish long press from drag from gesture from multi ...
Read more >How to Detect Long Press Gestures in JavaScript Events in ...
So let's work through this step by step: Cancel our long press timeout if we know it's not a long press; Prevent our...
Read more >Long press on new tab not working : r/chrome - Reddit
So I used to scroll through the cards on the new tab page when I was bored, opening anything I found interesting by...
Read more >Long press to open in new tab has stopped working
I used to be able to open a link into a new tab on my phone by long pressing on it to get...
Read more >How to enable the long press back button to show the history ...
You'll find that if you go to the play store and uninstall Chrome, it'll remove all recent updates, which seemed to be the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi! The linked PR should fix most of the issues. What’s still not fixed are touch events (
onTouches...
), as that will require more research to see if implementing it usinghammerjs
is feasible.Okay, sounds good, I created the new issue here: https://github.com/software-mansion/react-native-gesture-handler/issues/2263