如何在React Native中获取可滑动手势值

时间:2019-08-07 07:41:26

标签: react-native

当我从左侧滑动时如何在本机反应中获得可滑动手势值 下面的代码

<Swipeable
    renderLeftActions={LeftActions}
     onSwipeableLeftOpen={onSwipeFromLeft}
     renderRightActions={(progress, dragX) => (
    <RightActions progress={progress} dragX={dragX} onPress= 
       {onRightPress} />
      )}
        >

1 个答案:

答案 0 :(得分:1)

我使用了react-native-swipe-gestureshttps://github.com/glepur/react-native-swipe-gestures),它在基本的4个方向滑动(上,下,左,右)上提供了良好的支持

您可以这样使用它:

import GestureRecognizer from 'react-native-swipe-gestures';

<GestureRecognizer
    onSwipe={swipeHandler}
    onSwipeLeft={leftSwipeHandler}
    onSwipeRight={rightSwipeHandler}
    onSwipeUp={upSwipeHandler}
    onSwipeDown={downSwipeHandler}
>
    ...swipable area...
</GestureRecognizer>

“ onSwipe”方法调用带有参数(gestureName, gestureState)的函数,并用于所有滑动动作。所有其他一个特定于方向的onSwipe方法都使用gestureState参数调用函数。

gestureName是您可以用来判断已向哪个方向滑动的基本信息,它可以是以下任意值:SWIPE_UP,SWIPE_DOWN,SWIPE_LEFT,SWIPE_RIGHT和null(对于任何其他类型的滑动)