class WrappedCell extends React.Component{
translateX = new Animated.Value(0);
_panResponder = PanResponder.create({
onMoveShouldSetResponderCapture: () => true,
onMoveShouldSetPanResponderCapture: () => true,
onPanResponderMove: (e, gestureState) => {
Animated.event([null, {dx: this.translateX}])(e, gestureState)
},
onPanResponderTerminate: (e, gestureState) => {
this._onReleased(e, gestureState);
},
onPanResponderRelease: (e, gestureState) => {
this._onReleased(e, gestureState);
},
});
现在,我的平移响应器允许两个方向。如何修改onPanResponderMove
,使其仅允许向右方向?
答案 0 :(得分:1)
尝试这样的事情:
onPanResponderMove: (e, gestureState) => {
if(gestureState.dx > 0)
Animated.event([null, {dx: this.translateX}])(e, gestureState)
},