[英]PanResponder React native parameters
我的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}
);
}
我想知道什么時候我在函數_handlePanResponderMove我的數組的ID的值,但我不能給函數參數
handlePanResponderMove中的event參數為您提供觸摸目標的節點ID。 即Event.nativeEvent.target可以幫助您。
里面你componentTag
你使用this
關鍵字,要做到這一點,你需要綁定this
給你的方法。
您需要一個類似以下的構造函數:
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.