glepur/react-native-swipe-gestures

onPress, onClick, onSelect is missing

mayurkothule opened this issue · 1 comments

onPress event missing.
Is there any way to get onPress/onClick callback from child component of <GestureRecognizer/>
e.g

<GestureRecognizer
         onSwipeLeft={state => this.onSwipeLeft(state)}
         onSwipeRight={state => this.onSwipeRight(state)}
         config={config}
       >
     <TouchableOpacity  onPress={this.onViewClick.bind(this)}>
       <Text >{this.props.text}</Text>
     </TouchableOpacity>     
  </GestureRecognizer>

OR

<GestureRecognizer
          onSwipeLeft={state => this.onSwipeLeft(state)}
          onSwipeRight={state => this.onSwipeRight(state)}
          onPress={this.onViewClick.bind(this)}
          config={config}
        >
        <Text >{this.props.text}</Text>
  </GestureRecognizer>

A temporary work around to handle click/press events

  1. Open node_modules/react-native-swipe-gestures/index.js
  2. Edit the method _shouldSetPanResponder to look like this

_handleShouldSetPanResponder(evt, gestureState) {
    if (this._gestureIsClick(gestureState)  && this.props.onPressGesture) {
      return this.props.onPressGesture();
    }

    return (
      evt.nativeEvent.touches.length === 1 &&
      !this._gestureIsClick(gestureState)
    );

  }
  1. Update your component where you used GestureRecognizer to look like this
` <GestureRecognizer
        onPressGesture={() => {/* handle your press/click event here */}}
        ...

`