onPanResponderRelease不在Android设备上工作

时间:2017-11-24 06:00:30

标签: android ios react-native

当我在iOS设备上使用panResponders时,它可以正常工作,但是当我在Android设备上运行时它的代码相同,它没有按预期工作。代码如下

componentWillMount() {
    this._panResponder = PanResponder.create({
        onStartShouldSetPanResponder: (evt, gestureState) => true,
        onStartShouldSetPanResponderCapture: (evt, gestureState) => true,
        onMoveShouldSetPanResponder: (evt, gestureState) => true,
        onMoveShouldSetPanResponderCapture: (evt, gestureState) => true,

        onPanResponderGrant: (evt, gestureState) => {
            return true;
        },
        onPanResponderTerminationRequest: (evt, gestureState) => {
            console.log('getting on android');
            return false;
        },
        onPanResponderRelease: (evt, gestureState) => {
            console.log('getting here')
            return true;
        },
        onPanResponderTerminate : (evt, gestureState) => {
            console.log('gets');
        }
    });
}

此外,我的scrollView代码段如下所示。

<ScrollView
      ref={ref => this.myScroll = ref }
      {...this._panResponder.panHandlers}>

1 个答案:

答案 0 :(得分:0)

要使其正常工作,请使用onPanResponderEnd而不是onPanResponderRelease

此外,如果我们仍然想使用onPanResponderRelease,则应通过以下方式允许终止请求:

onPanResponderTerminationRequest: () => true