christopherabouabdo / react-native-simple-gesture

Wrapper for React Native gestureState that provides information about the type of gesture using a simple plain english API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

(noob) Moaaar complete example

polmoneys opened this issue · comments

commented

aloha from Barcelona

is there a chance you could share how to listen to 4 events (swipeUp,swipeDown,swipeRight,swipeLeft) and trigger a different response for each?

I've tried to listen to the evt onPanResponderRelease and switch between the values with no success :(

TIA

@polmoneys if you still need help this is what I did to handle the different gestures:

componentDidMount = () => {
     this._panResponder = PanResponder.create({
      onMoveShouldSetResponderCapture: () => true,
      onMoveShouldSetPanResponderCapture: () => true,
      onStartShouldSetPanResponder: this._handleStartShouldSetPanResponder,
      onMoveShouldSetPanResponder: this._handleMoveShouldSetPanResponder,
      onPanResponderGrant: this._handlePanResponderGrant,
      onPanResponderMove: this._handlePanResponderMove,
      onPanResponderRelease: this._handlePanResponderEnd,
      onPanResponderTerminate: this._handlePanResponderEnd,
    });
}

 _handlePanResponderMove = (e: Object, gestureState: Object) => {
  let sgs = newSimpleGesture(e, gestureState);
  if (sgs.isSwipeRight()) {
    console.log('is swipe right');
} else if (sgs.isSwipeLeft()) {
    console.log('is swipe left')
}

Is not a complete example but it should give you a good idea.

commented

@jqn thanks for your input but can't make it work :(
I'll take another round tomorrow...

commented

YAY IT WORKED ! !