react-native-slider icon indicating copy to clipboard operation
react-native-slider copied to clipboard

Augment the hitSlop or prevent parent gesture listener to react around slider

Open zabojad opened this issue 4 years ago • 20 comments

I'm using a slider within a swiper and it's quite hard to slide the slider without triggering the swiper.

How could I improve that situation ?

Is there some kind of hitSlop prop equivalent on the slider?

If not, how could I workaround this problem?

zabojad avatar Aug 02 '21 16:08 zabojad

Note that it is actually a problem on Android, not on iOS...

zabojad avatar Aug 03 '21 10:08 zabojad

Does anyone have a solution? I'm still looking for it...

zabojad avatar Aug 20 '21 09:08 zabojad

@zabojad Can you provide a minimal example or a part of your code? I will take a look into that.

BartoszKlonowski avatar Aug 20 '21 09:08 BartoszKlonowski

hey @BartoszKlonowski ! Thanks for taking the time to help me.

Here is a reproducer : https://snack.expo.dev/5jW86cV70

I've not included the react-native-swiper dependency because it is actually just a ScrollView...

So let me recap the issue : when nested in an horizontal ScrollView, there is no way to give the priority to the react-native-slider instance for touch events... This happens only on Android. It's fine on iOS.

zabojad avatar Aug 20 '21 10:08 zabojad

@zabojad That is a good example, thank you! As I can see it is possible to reach the slider with a touch event, but dragging is captured by a parent. Let me take some time to dig in and I will come back to you.

BartoszKlonowski avatar Aug 20 '21 10:08 BartoszKlonowski

Hej @BartoszKlonowski ! Did you find anything regarding this issue, by any chance?

zabojad avatar Aug 23 '21 11:08 zabojad

I've opened another issue in RN issue tracker.

zabojad avatar Aug 27 '21 09:08 zabojad

@zabojad Sorry for a delay, but yes, I found that this behavior is caused by a native layout structure and is typical for a native Android solutions. I also found some code samples that would need to be applied to this library, but we will need to spend some time to implement this.

You created an issue in RN repository - let's see if someone will provide you with a decent solution or at least workaround, but in the worst case let's accept if the issue will be closed as the responsibility for this feature is most probably on our side.

BartoszKlonowski avatar Aug 27 '21 11:08 BartoszKlonowski

@BartoszKlonowski thank you for your answer. I just checked out the Android sources of this module. Can you please describe what should be done exactly?

zabojad avatar Aug 27 '21 12:08 zabojad

@BartoszKlonowski sorry to ask you again, but I could probably help on this topic if you describe me what has to be done...

zabojad avatar Sep 03 '21 07:09 zabojad

@zabojad I was trying to find a way that would not require manipulating the ScrollView from a SeekBar, because from my research it turns out that what needs to be done is to block or revert a progress of ScrollView each time the SeekBar is changed. But the thing is that I can't find a way to access the parent ScrollView from a native implementation of SeekBar View Manager - that's the case.

BartoszKlonowski avatar Sep 03 '21 10:09 BartoszKlonowski

But the thing is that I can't find a way to access the parent ScrollView from a native implementation of SeekBar View Manager - that's the case.

@BartoszKlonowski Could we somehow pass the slider a ref to the scrollview from js?

zabojad avatar Sep 28 '21 15:09 zabojad

@BartoszKlonowski sorry to disturb you again, could you share the details of what you've found out so that I could try to continue searching for a solution?

zabojad avatar Oct 07 '21 12:10 zabojad

@zabojad I'm back, sorry. I believe that this SO answer described the best what should be done. I think that we should somehow force the View to use this requestDisallowInterceptTouchEvent.

BartoszKlonowski avatar Oct 19 '21 23:10 BartoszKlonowski

was anyone able to fix this ? I am facing the same issue

tushar-singhal avatar Nov 18 '21 10:11 tushar-singhal

Solution that works for me, added this as a slider prop onResponderGrant={() => true}

ykvarts avatar Dec 26 '21 00:12 ykvarts

@ykvarts solution didn't work for me :/

blazk0 avatar May 26 '22 10:05 blazk0

In my case, the parent is PanGestureHandler which was overriding the Slider gesture. Giving a minDist={20} to it fixed it for me

blazk0 avatar May 26 '22 11:05 blazk0

@ykvarts solution didn't work for me :/

Solution that works for me, added this as a slider prop onResponderGrant={() => true}

thank you it works fine for me now

kien-nt0306 avatar Jul 04 '23 08:07 kien-nt0306