software-mansion / react-native-gesture-handler

Declarative API exposing platform native touch and gesture system to React Native.
https://docs.swmansion.com/react-native-gesture-handler/
MIT License
6.12k stars 979 forks source link

Swipeable hit Threshold #829

Closed vishva-shukla closed 2 years ago

vishva-shukla commented 5 years ago

Hi, I want the icon to go from 50% to 100% when swipe reach to Threshold. Is there any event to know when swipe hit the Threshold. I don't want to perform animation just increase and decrease size of icon according to threshold

For example Screen Shot 2019-11-06 at 5 02 30 PM

Jakegillingham5 commented 4 years ago

Did you manage to find a solution?

vishva-shukla commented 4 years ago

not yet

garrytaulu commented 4 years ago

I would love to know this as well to help achieve a more native feel to the gesture. On iOS when you hit the 50% threshold not only does the text move but the haptics fire to let you know "hey, letting go here means you're committing to the action".

This would help a lot with the mental model of our users when they use the swipe gesture.

kmagiera commented 2 years ago

Hi all. I am not sure what an exact issue here is. I'd recommend however taking a look at examples of using gesture handler with reanimated. With reanimated you can use even callbacks to monitor and react to any kind of conditions i.e. get current progress and take some action when it crosses certain threshold; you should also be able to fire haptic direct from reanimated event callback

Ronuhz commented 1 year ago

Has this been added? I would also want to play a haptic when the Threshold is hit so the user will know that the action will happen .

aldensully commented 1 year ago

@Ronuhz this is how im doing it

const panGesture = Gesture.Pan()
    .onUpdate((e) => {
      if (offsetX.value < threshold) {
        if (hasReachedThreshold.value === false) {
          runOnJS(Haptics.impactAsync)(Haptics.ImpactFeedbackStyle.Medium);
          hasReachedThreshold.value = true;
        }
      } else {
        hasReachedThreshold.value = false;
      }
      offsetX.value = e.translationX + startX.value;
    })
Ronuhz commented 1 year ago

@aldensully

Okay, I'm currently using the Swipeable component cause it doesn't conflict with ScrollView. I knew how to make it from scratch with the PanGestureHandler but not with the GestureDetector, so I would appreciate if you could lighten me up. Thanks

aldensully commented 1 year ago

@Ronuhz i made a lil repo with the component files if you wanna see how im doing it. lmk if you have questions https://github.com/aldensully/swipeable-list

Ronuhz commented 1 year ago

@aldensully Thank you. The repo helped a lot.

Ronuhz commented 1 year ago

@aldensully your solution regarding the hit threshold works perfectly but now I'm having the problem that I can no longer use the scroll view to scroll through the items, neither with the scroll view from react native nor from react native gesture handler.

aldensully commented 1 year ago

@Ronuhz I had the same issue, playing with the values for activeOffsetX([-20, 20]) on the Gesture fixed the issue for me. Though I didnt test this on android.