question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Buttons do not trigger onPress if inside TapGestureHandler

See original GitHub issue

I have BaseButton inside a TapGestureHandler.

In Android, pressing the button will trigger both onHandlerStateChange from TapGestureHandler and onPress & onActiveStateChange from BaseButton.

In iOS, pressing the button triggers the onHandlerStateChange from TapGestureHandler and the onActiveStateChange from BaseButton. However, onPress is never triggered.

I added the waitFor but I still get the same result. Any help?

btnRef = React.createRef()

{...}

render() {
   return (
      <TapGestureHandler onHandlerStateChange={this.onHandlerStateChange} /* waitFor={this.btnRef} */>
         {...}
         <BaseButton
           // ref={this.btnRef}
           onPress={onPress}
           onActiveStateChange={this.onActiveStateChange}
           style={style}
           enabled={enabled}
           {...otherProps}
         >
           {this.props.children}
         </BaseButton>
         {...}
      </TapGestureHandler>
)}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:15
  • Comments:8

github_iconTop GitHub Comments

2reactions
mardikarifqicommented, Aug 14, 2021

Are there any updates for this?

0reactions
p-sebastiancommented, Sep 13, 2022

For anyone still looking for this:

Using the react-native-gesture-handler buttons, you can use the prop disallowInterruption which will cancel parent gesture handler events

<GestureDetector gesture={gesture}>
  ... // some content
  <RectButton disallowInterruption>...</RectButton>
</GestureDetector>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Buttons do not trigger onPress if inside TapGestureHandler
I have BaseButton inside a TapGestureHandler. In Android, pressing the button will trigger both onHandlerStateChange from TapGestureHandler ...
Read more >
React Native TapGestureHandler - how to call a function and ...
If i do that it says this2.onButtonClicked is not a function. Maybe it is possible to call the Animated.Event from a function? –...
Read more >
Buttons | React Native Gesture Handler - Software Mansion
Gesture handler library provides native components that can act as buttons. These can be treated as a replacement to TouchableHighlight or TouchableOpacity ...
Read more >
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 >
#14 Custom Tap Gesture — React Native Fashion - YouTube
In this series, we are building a React Native App from 0 to 1.The source code is available via the Start React Native...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found