react-native-page-listview是一个能很好实现上拉下拉的功能的插件,可是存在在部分真机上,在列表没有滚动时,不能触发onPress。通过对插件源码分析,发现在开始移动时判断是否设置当前的View为手势响应者时没有对点击事件做判断,所以在onMoveShouldSetPanResponder加入一个dy=0时的情况判断,就能很好的解决onPress不能触发的情况。
//开始移动时判断是否设置当前的View为手势响应者
onMoveShouldSetPanResponder=(e,gesture)=> {
// if(!this.props.pageLen)return false;
let {dy}=gesture; let bool;
if(dy<0){//向上滑
if(this.state.pullState!=='noPull'){
this.resetAni();
}
!this.state.scrollEnabled&&this.setState({scrollEnabled:true});
bool=false;
}else if(dy==0){
bool=false;
}else {//向下拉
if(this.state.pullState!=='noPull'){
bool=true;
}else {
bool=!this.state.scrollEnabled||this.lastListY<1;
} }
return bool;
};