如何将平移响应器仅移至顶部和左侧

时间:2018-12-12 17:36:45

标签: react-native gesture pan

如何限制平底锅的移动区域仅向上(顶部)和左侧响应?

我目前正在这样做,但没有成功!

this.state = 
{
  pan: new Animated.ValueXY()
}    

let eventMoveLeft = Animated.event
(
  [null, { dx: this.state.pan.x}]
);

let eventMoveTop = Animated.event
(
  [null, { dy: this.state.pan.y}]
);

onPanResponderMove: (e, gesture) => {
if (this.state.isAnimated) {
      return gesture.dx < gesture.dy ? eventMoveLeft(e, gesture) : eventMoveTop(e, gesture);
    }
  },

1 个答案:

答案 0 :(得分:1)

onPanResponderMove事件获取设备的高度并以百分比限制所需的距离,像这样...

 Math.abs(gesture.dy) > HEIGHT_DEVICE * .16 ? null : this.state.pan.y.setValue(gesture.dy);