Skip to content

panResponder calls move handlers while simple tapping #13756

Description

@karpoff

I'm using pan responder to handle touches and I see that it raises move events while simple tapping on Android

please see code above

export default class extends Component {
    componentWillMount() {
        this._panResponder = PanResponder.create({
            onStartShouldSetPanResponder: this._handleStartShouldSetPanResponder,
            onMoveShouldSetPanResponder: this._handleMoveShouldSetPanResponder,
            onPanResponderGrant: this._handlePanResponderGrant,
            onPanResponderMove: this._handlePanResponderMove,
            onPanResponderRelease: this._handlePanResponderEnd,
            onPanResponderTerminate: this._handlePanResponderEnd,
        });
    }

    _handleStartShouldSetPanResponder = (e, ges) => {
        console.log("should start", e.nativeEvent, ges);
        return false;
    };
    _handleMoveShouldSetPanResponder = (e, ges) => {
        console.log("should move", e.nativeEvent, ges);
        return true;
    };
    _handlePanResponderGrant = e => {
        console.log("grant", e.nativeEvent);
    };
    _handlePanResponderMove = e => {
        console.log("move", e.nativeEvent);
    };
    _handlePanResponderEnd = e => console.log("end", e.nativeEvent);

    render() {
        return (
            <View style={{flex: 1, justifyContent: "center", alignItems: "center", backgroundColor: "#eee"}} {...this._panResponder.panHandlers}>
                <TouchableOpacity onPress={() => alert("click")}><Text>click</Text></TouchableOpacity>
            </View>
        );
    }
}

I want to handle touch moves only and single taps should be passed to child component
But I see that it is quite difficult to do single tap (so it will be handled by TouchableOpacity) Because most of the time when I tap my device, move events are raised by PanResponder so TouchableOpacity doesn't works.
I tried to distinguish single taps and moves in onMoveShouldSetPanResponder handler (so I can return false in single tap case) but I see no difference in event argument

I think that timeout between tapping and raising move event is too small and should be increased (or maybe configured)

  • React Native version: 0.44
  • Platform: Android
  • Development Operating System: Windows

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions