【问题标题】:React-Native How to only trigger the click on an TouchableOpacity when the tap releaseReact-Native如何在点击释放时仅触发对TouchableOpacity的点击
【发布时间】:2019-05-19 16:50:05
【问题描述】:

我正在制作一个类似于火种卡的系统,您可以左右滑动,但现在我想添加一种点击方式。当我添加一个 touchableOpacity 时,我无法再移动它,因为当我将手指放在它上面时,它会改变视图的不透明度并被阻止。

基本上我尝试使用 touchableHighlight 但没有任何改变

所以我有:

<Animated.View>
  <TouchableOpacity>
    //Stuff here
  </TouchableOpacity>
</Animated.View>

我希望卡片仍然能够移动,并且只有在我真正想要点击时才触发点击

【问题讨论】:

  • 你有什么解决办法吗?

标签: react-native touchableopacity react-animations


【解决方案1】:

已有组件 react-native-swipe-gestures 用于处理上下左右方向的滑动手势,见https://github.com/glepur/react-native-swipe-gestures

所以直接不行,但你可以参考下面的代码:

 <GestureRecognizer
        onSwipe={(direction, state) => this.onSwipe(direction, state)}
        onSwipeUp={(state) => this.onSwipeUp(state)}
        onSwipeDown={(state) => this.onSwipeDown(state)}
        onSwipeLeft={(state) => this.onSwipeLeft(state)}
        onSwipeRight={(state) => this.onSwipeRight(state)}
        config={config}
        style={{
          flex: 1,
          backgroundColor: this.state.backgroundColor
        }}
        >
         // enter code here
      </GestureRecognizer>

【讨论】:

  • 这不是我所要求的,手势在我的卡上工作问题是当我将手指放在卡上时添加 TouchableOpacity 时它按下 Touchable 所以我不能移动它
猜你喜欢
  • 2018-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-01
  • 1970-01-01
  • 2018-06-30
  • 1970-01-01
相关资源
最近更新 更多