Skip to content

[Touchable] How to stopPropagation touch event #1046

Closed
@magicismight

Description

@magicismight
Contributor

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;
  }
});

Activity

joewood

joewood commented on May 30, 2015

@joewood

Having the same issue. I'm wondering if ShouldCapture events should return true if the movement is more horizontal than vertical. The documents are not great for the PanResponder API.

changed the title [-]How to stopPropagation touch event[/-] [+][Touchable] How to stopPropagation touch event[/+] on May 30, 2015
self-assigned this
on May 30, 2015
ghost

ghost commented on Aug 4, 2015

@ghost

Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.

ericvicenti

ericvicenti commented on Aug 4, 2015

@ericvicenti
Contributor

PanResponder.create({ will return an object, and you need to render a view with the responder handlers on it. For exmple:

componentWillMount: function() {
  this.gesture = PanResponder.create({ ... });
}
render: function() {
  return (
    <View {...this.gesture.panHandlers} ... />
  );
},

preventDefault does not enable the touch responsiveness we want on native mobile. To make actions clear to the user, components should visibly respond for a given touch, and give up responder if something else needs it. Although the touch responder API isn't perfect, it should work for most things.

Can you be more specific about what you are trying to do? Maybe post a minimal example of the issue on rnplay.org?

If you have any improvements to the gesture guide or the pan responder docs, feel free to make a pull request!

brentvatne

brentvatne commented on Sep 10, 2015

@brentvatne
Collaborator

@ericvicenti - I've had this issue myself as well - for example:

screen shot 2015-09-10 at 10 43 13 am

Inside of the horizontal ScrollView, at the bottom of each page there is a footer that can be pulled upwards. If you start pulling this up (onStartShouldSetPanResponder returns true) then the ScrollView should not do respond to any movement. The only solution I have for this right now is to lock the ScrollView when the gesture begins, and unlock it when it's released. There is a slight problem with this solution still because if you do just the right gesture so that it scrolls the ScrollView a little bit before setting the responder and locking the ScrollView, you end up in a weird state where you're locked in between pages. To handle this, I need to track the active page in the ScrollView and scroll it back to the right position when I lock it.

The best solution would be to just be able to have the PanResponder become responder and block ScrollView. @vjeux mentioned that on Android there is a ~5px delay when the gesture starts before the ScrollView takes over, which gives the PanResponder a chance to respond. Maybe a similar solution is needed for iOS.

jukkatupamaki

jukkatupamaki commented on Jan 9, 2016

@jukkatupamaki

While trying to move a SliderIOS's knob, Navigator starts the swipe back gesture at the same time. Using PanResponder to catch the touch start doesn't seem to help.

propagation-stop-bug

componentWillMount: function() {
    this._panResponder = PanResponder.create({
        onStartShouldSetPanResponder: (evt, gestureState) => true,
        onStartShouldSetPanResponderCapture: (evt, gestureState) => true,
        onMoveShouldSetPanResponder: (evt, gestureState) => true,
        onMoveShouldSetPanResponderCapture: (evt, gestureState) => true
    });
}
<SliderIOS {...this._panResponder.panHandlers} />

Even though I use PanResponder to capture the touch event, the onMoveShouldSetPanResponder callback gets called in Navigator (

this._expectingGestureGrant =
this._matchGestureAction(this._eligibleGestures, sceneConfig.gestures, gestureState);
return !!this._expectingGestureGrant;
).

jukkatupamaki

jukkatupamaki commented on Jan 10, 2016

@jukkatupamaki

uiexplorer-slider-bug

I just noticed that the same bug exists in the UIExplorer example.

casperin

casperin commented on Jan 29, 2016

@casperin

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,
  });
}
rameshvishnoi90904

rameshvishnoi90904 commented on Mar 3, 2016

@rameshvishnoi90904

I also want to do same thing(Stop Panresponder after a given event).Please Help

44 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @bentomas@brentvatne@casperin@getnashty@brunoreis

        Issue actions

          [Touchable] How to stopPropagation touch event · Issue #1046 · facebook/react-native