Touch events don't bubble up when nesting TouchableHighlight components
See original GitHub issueI would expect unhandled touch events to bubble up to the parent when a given TouchableHighlight component doesn’t handle them. All the events currently stop at the direct container.
<TouchableHighlight onLongPress={this._onLongPress}>
<TouchableHighlight onPress={this._onPress}>
<Text>
Press or LongPress me
</Text>
</TouchableHighlight>
</TouchableHighlight>
Is there a particular reason why we don’t allow the events to bubble up and enable the above scenario?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:6
- Comments:11 (1 by maintainers)
Top Results From Across the Web
How can I propagate touch event in nested Touchable in ...
I am not sure I understand the question but try using event.preventDefault on the outer touchable highlight, to only access the inner one....
Read more >React Nested Component Touch Event Stop Propagation Is Not ...
The stopPropagation method prevents propagation of the same event from being called. Propagation means bubbling up to parent elements or capturing down to....
Read more >Event Bubbling and Event Catching in JavaScript and React
In this article, I'll help you understand event bubbling and event catching like a ... Which Events Do Not Bubble and How Are...
Read more >React Native touchable vs. pressable components
Learn the difference between touchable and pressable components in React ... touch events via buttons and other interactive UI elements.
Read more >press event passes through overlaying <View/> on andriod ...
How to Bubbling press event from inner Touchable to outer Touchable in React-Native? ... How to trigger another Touchable component's press event by...
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 Free
Top 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
Somewhat related, check out this great talk by Andy Matuschak about the challenges of implementing a gesture system.
So this is what I think is going on: the touchable state is local to the touchable component, and touchable components are completely unaware of others and eager to become responder for any touch event that is given to it. Currently, there can only be one responder for any touch event. So when you touch the inner
TouchableHighlight
, it captures the touch which prevents the outer component from even having a chance to transition from the “not responder” state of its state machine. When you release the touch, it simply ends the gesture.My guess would be that it is a simple model that works most of the time. Maybe @vjeux can speak more to this.
I’m actually not sure that this approach would work and don’t have time at the moment to look into it 😦 Let me know if you find a solution to it.
This issue seems like it has been sufficiently answered, so I am going to close it.