react-native-scrollable-tab-view和listview冲突解决

react-native-scrollable-tab-view和listview冲突解决

问题描述

listview向下拉时,会造成react-native-scrollable-tab-view插件的内容左右滑动,进而listview的下拉滑动失效,做不成下拉刷新功能

解决思路

listview滑动时,判断滑动方向,如果是下拉就屏蔽react-native-scrollable-tab-view左右滑动的功能,等下拉时间结束时再开启

如果方向是左右就开启react-native-scrollable-tab-view左右滑动的功能

代码

判断listview滑动方向

<GiftedListView
    ref="giftedListView"
    rowView={this._renderRowView}
    onFetch={this._onFetch}
    firstLoader={true}
    pagination={true}
    refreshable={true}
    initialListSize={8}
    withSections={false}
    renderSeparator={this._renderSeparatorView}
    onTouchStart={(e) => {
        this.pageX = e.nativeEvent.pageX;
        this.pageY = e.nativeEvent.pageY;
    }}
    onTouchMove={(e) => {
        if(Math.abs(this.pageY - e.nativeEvent.pageY) > Math.abs(this.pageX - e.nativeEvent.pageX)){ // 下拉
            this.props.lockSlide();
        } else { // 左右滑动
            this.props.openSlide();
        }
    }}
    customStyles={{
        paginationView: {backgroundColor: '#F9F9FA', },
        refreshableView: {backgroundColor: '#F9F9FA', },
    }}
    rowHasChanged={(r1,r2)=>{r1.id !== r2.id}}
    refreshableTintColor="blue"
    emptyView={this._renderEmptyView}
    paginationFetchingView={this._renderPaginationFetchigView}
    paginationAllLoadedView={this._renderPaginationAllLoadedView}
    paginationWaitingView={this._renderPaginationWaitingView}
    onEndReached={this._onEndReached}
    onEndReachedThreshold={1}>
</GiftedListView>
	主要方法是onTouchStart,onTouchMove

    屏蔽react-native-scrollable-tab-view左右滑动
	需要在react-native-scrollable-tab-view组件的源码中添加一个方法(方法名称随意)
	
setNativeProps: function(scroll) {
  if(scroll){
    this.scrollView.setNativeProps({
      scrollEnabled: true,
    });
  } else {
    this.scrollView.setNativeProps({
      scrollEnabled: false,
    });
  }
},
    调用
_lockSlide(){
    this.refs.scrollTabView.setNativeProps(false);
}

_openSlide(){
    this.refs.scrollTabView.setNativeProps(true);
}














  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值