How to make TapGestureHandler work correctly in functional components?
See original GitHub issueI have this very simple tap listener for:
- single tap
- double tap
written in functional component.
const PressBox = () => {
const doubleTapRef = React.createRef();
const _onSingleTap = (event) => {
if (event.nativeEvent.state === State.ACTIVE) {
alert("I'm touched");
}
};
const _onDoubleTap = (event) => {
if (event.nativeEvent.state === State.ACTIVE) {
alert('D0able tap, good job!');
}
};
return (
<TapGestureHandler onHandlerStateChange={_onSingleTap} waitFor={doubleTapRef}>
<TapGestureHandler ref={doubleTapRef} onHandlerStateChange={_onDoubleTap} numberOfTaps={2}>
<View style={styles.box} />
</TapGestureHandler>
</TapGestureHandler>
);
};
Problem
Double-tap never gets fired. Only single taps
Expected
_onDoubleTap
to fire on double tap
Issue Analytics
- State:
- Created 3 years ago
- Comments:8
Top Results From Across the Web
React Native Gesture Handler: Swipe, long-press, and more
Implementing gestures in a React Native app improves the user experience. Learn how to create swipeable, pan, long-press, and other ...
Read more >React Native TapGestureHandler - how to call a function and ...
You can achieve this using a inline callback function and which inturns call ... Also Make sure, You bind this variable properly inside...
Read more >How to Use Functional Components in React - freeCodeCamp
Have you wondered how to create a component in React? To answer, it is as simple as creating a function returning an HTML-like...
Read more >React Functional Components: In-Depth Guide - KnowledgeHut
React functional components are just normal JavaScript functions; we can create them using specific function keywords. Most developers create ...
Read more >Buttons | React Native Gesture Handler - Software Mansion
Gesture handler library provides native components that can act as buttons. ... function that gets triggered when button changes from inactive to active...
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
For anyone who ends up here looking for a solution,
React.useRef()
hook is needed instead ofReact.createRef()
;Made it work… I had to abstract out all the logic into its own separate component… That made it work.