Gesture.Tap().maxDuration(...) not working on web
See original GitHub issueDescription
Using maxDuration()
on a Tap gesture doesn’t seem to work on web.
Platforms
- iOS
- Android
- Web
Screenshots
Steps To Reproduce
Run the code example below on the web then tap and hold on the red circle.
Expected behavior
For it to behave the same as on native where if the tap is held longer than the maxDuration
value, the onTouchesCancelled
callback is called followed by the onFinalize
callback being called.
Actual behavior
On web, the tap can be held forever without ever being canceled.
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 wasCancelled = useSharedValue(false)
const wasFinalized = useSharedValue(false)
const tapGesture = Gesture.Tap()
.maxDuration(500)
.onBegin(() => {
isPressed.value = true
wasCancelled.value = false
wasFinalized.value = false
})
.onTouchesCancelled(() => {
wasCancelled.value = true
})
.onFinalize(() => {
isPressed.value = false
wasFinalized.value = true
})
const wasCancelledAnimatedStyles = useAnimatedStyle(() => ({
opacity: wasCancelled.value ? 1 : 0,
}))
const wasFinalizedAnimatedStyles = useAnimatedStyle(() => ({
opacity: wasFinalized.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={wasCancelledAnimatedStyles}>
<Text style={styles.text}>`onTouchesCancelled()` was called.</Text>
</Animated.View>
<Animated.View style={wasFinalizedAnimatedStyles}>
<Text style={styles.text}>`onFinalize()` was called.</Text>
</Animated.View>
<GestureDetector gesture={tapGesture}>
<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:7 (3 by maintainers)
Top Results From Across the Web
react native - How to stop propagation of Gesture.Tap()?
Here is a minimal example of how I tried to set up two nested GestureDetector with Gesture.Tap() gestures. import React from 'react'; import ......
Read more >Camera - Expo Documentation
Run the example on your device to see all these features working together! ... one of maxDuration and maxFileSize is reached or camera...
Read more >Tap gesture | React Native Gesture Handler - Software Mansion
A discrete gesture that recognizes one or many taps. Tap gestures detect one or more fingers briefly touching the screen. The fingers involved...
Read more >A guide to delaying gestures in ScrollView - Hacking with Swift
Motivation. A gesture inside a scrolling view will hijack scrolling if the gesture is configured to be recognised first:
Read more >Recognize a tap gesture - .NET MAUI - Microsoft Learn
NET Multi-platform App UI (.NET MAUI) tap gesture recognizer is used for tap detection and is implemented with the TapGestureRecognizer class.
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
It’s similar situation to https://github.com/software-mansion/react-native-gesture-handler/issues/2063#issuecomment-1131475881. If you want to know whether the gesture ended successfully or was cancelled you can use the second argument of
onEnd
andonFinalize
callbacks, for example:Okay, sounds good, I created the new issue here: https://github.com/software-mansion/react-native-gesture-handler/issues/2263