当我在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}>
答案 0 :(得分:0)
要使其正常工作,请使用onPanResponderEnd
而不是onPanResponderRelease
。
此外,如果我们仍然想使用onPanResponderRelease
,则应通过以下方式允许终止请求:
onPanResponderTerminationRequest: () => true