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.

[Touchable] How to stopPropagation touch event

See original GitHub issue

I have a ScrollView which contains a View inside. When I move touch on the View, It will scroll the ScrollView too. I woner is there a way to stopPropagation just like the DOM event does. I have tried to set PanResponder like this,but It didn`t work

PanResponder.create({
  onStartShouldSetPanResponder:  function () {
    return false;
  },
  onStartShouldSetPanResponderCapture: function () {
    return false;
  },
  onMoveShouldSetPanResponder:  function () {
    return false;
  },
  onMoveShouldSetPanResponderCapture: function () {
    return false;
  },
  onPanResponderTerminationRequest: function () {
    return false;
  }
});

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:33 (3 by maintainers)

github_iconTop GitHub Comments

34reactions
nulleofcommented, Nov 15, 2016

I use

this.scrollView.setNativeProps({ scrollEnabled: false } inside onPanResponderGrant and this.scrollView.setNativeProps({ scrollEnabled: true } inside onPanResponderRelease.

this.scrollView is set inside ref: <ScrollView ref={(c) => { this.scrollView = c; }} >

It works much faster than setting state variable and there is no scroll movement even if you swipe fast.

16reactions
casperincommented, Jan 29, 2016

I had the same problem. This response solved it for me. Essentially same as @tukkajukka’s solution above, only with

componentWillMount () {
  this._panResponder = PanResponder.create({
    onPanResponderTerminationRequest: () => false,
    onStartShouldSetPanResponderCapture: () => true,
  });
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Touch events - Web APIs - MDN Web Docs - Mozilla
One technique for preventing things like pinchZoom on a page is to call preventDefault() on the second touch in a series. This behavior...
Read more >
How to bind 'touchstart' and 'click' events but not respond to both
Use of the preventDefault() or stopPropagation() method: This method prevents the event handler from responding to both touchstart and clicks ...
Read more >
Events and Mouse/Touch Events - The Web Platform Course
stopPropagation () , called to stop propagating the event in the DOM. and more. You can see the full list here. Each specific...
Read more >
touchstart Event - W3Schools
Example. Execute a JavaScript when the user touches a P element (for touch screens only):. <p ontouchstart="myFunction(event)">Touch me!</p>.
Read more >
Touch Events | Tizen Docs
Touch Events · touchstart handles an event which occurs when a finger comes in contact with the device screen. · touchmove handles an...
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