简体   繁体   English

PanResponder React本机参数

[英]PanResponder React native parameters

I have a problem with panResponder My code : 我的panResponder有问题我的代码:

componentWillMount() {
    this._panResponder = PanResponder.create({
      onStartShouldSetPanResponder: (evt, gestureState) => false,
      onStartShouldSetPanResponderCapture: (evt, gestureState) => true,
      onMoveShouldSetPanResponder: (evt, gestureState) => Math.abs(gestureState.dy) > 5,
      onMoveShouldSetPanResponderCapture: (evt, gestureState) => true,
      onPanResponderMove: this._handlePanResponderMove,
    });
  }

_handlePanResponderMove(event, gestureState) {
    if (gestureState.dy > current) {
      console.log("Down");
    } else {
      console.log("Up");
    }
    current = gestureState.dy;
  }

componentTag() {
   return tabTag.map((item, id) => {
      return(
        <View key={id} >
            <View {...this._panResponder.panHandlers}>
                <Icon name="ios-reorder" ></Icon>
            </View>
        </View>
      );
    });
}

render() {
   return (
     {this.componentTag}
   );
}

I would like to know when i am in the function _handlePanResponderMove the value of id of my array but i can't give parameters to the function 我想知道什么时候我在函数_handlePanResponderMove我的数组的ID的值,但我不能给函数参数

The event parameter in handlePanResponderMove Give you node id of the target of the touch. handlePanResponderMove中的event参数为您提供触摸目标的节点ID。 Ie Event.nativeEvent.target can help you with this. 即Event.nativeEvent.target可以帮助您。

Inside your componentTag you're using this keyword, to do that, you'll need to bind this to your method. 里面你componentTag你使用this关键字,要做到这一点,你需要绑定this给你的方法。

You need a constructor like following: 您需要一个类似以下的构造函数:

constructor() {
   this.componentTag = this.componentTag.bind(this);

   //since you're using this keyword on componentDidMount as well,
   this.componentWillMount = this.componentWillMount.bind(this);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM