can-it-be-done-in-react-native icon indicating copy to clipboard operation
can-it-be-done-in-react-native copied to clipboard

Question: How do you filter gestures (two finger for example)?

Open shawnmitchell opened this issue 5 years ago • 3 comments

In the Chrome Tab Sort demo, how would you restrict so that the PanGesture only started if two fingers?

Thanks!

shawnmitchell avatar Mar 09 '20 17:03 shawnmitchell

return (
    <PanGestureHandler {...gestureHandler}>
      <Animated.View
        style={{
          position: "absolute",
          top: 0,
          left: 0,
          width: TAB_SIZE,
          height: TAB_SIZE,
          justifyContent: "center",
          alignItems: "center",
          transform: [{ translateX }, { translateY }],
          zIndex
        }}
        onStartShouldSetResponder={(evt) => evt.nativeEvent.touches.length === 2}
      >
        <Tab {...{ tab }} />
      </Animated.View>
    </PanGestureHandler>
  );

I tried this, but no luck

shawnmitchell avatar Mar 09 '20 17:03 shawnmitchell

  return (
    <PanGestureHandler 
      {...gestureHandler}
      minPointers={2}
    >
      <Animated.View
        style={{
          position: "absolute",
          top: 0,
          left: 0,
          width: TAB_SIZE,
          height: TAB_SIZE,
          justifyContent: "center",
          alignItems: "center",
          transform: [{ translateX }, { translateY }],
          zIndex
        }}
      >
        <Tab {...{ tab }} />
      </Animated.View>
    </PanGestureHandler>
  );

Wow, super easy!

shawnmitchell avatar Mar 09 '20 18:03 shawnmitchell

Wanted this for a case where SortableTabs would be in a scroll view

shawnmitchell avatar Mar 09 '20 18:03 shawnmitchell