react-native-page-listview真機上點擊不能觸發onPress事件的bug解決

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){ //爲0時是點擊事件
       bool=false;    
}else {//向下拉       
     if(this.state.pullState!=='noPull'){  
          bool=true;      
      }else {    
          bool=!this.state.scrollEnabled||this.lastListY<1;     
       }    }   
 return bool;
};複製代碼
相關文章
相關標籤/搜索