React Native开发React Native开发经验集React-Native 开发阵营

react-native-scrollable-tab-view

2017-09-01  本文已影响1221人  45b645c5912e
<ListView
                        dataSource={this.state.dataSource}
                        onEndReached={this._loadMoreData}
                        renderFooter={this.renderFooter}
                        enableEmptySections={true}
                        onEndReachedThreshold={10}
                        renderRow={this._renderRow.bind(this)}
                        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();

                            }
                        }}
                        refreshControl ={
                            <RefreshControl
                                refreshing={this.state.isRefreshing}
                                onRefresh={this._loadAgainList}
                                title={'加载中...'}
                                titleColor={'#b1b1b1'}
                                colors={['#ff0000', '#00ff00', '#0000ff', '#3ad564']}
                                progressBackgroundColor={'#fafafa'}
                            />
                        }
                    />
  1. 首先需要在源码react-native-scrollable-tab-view源码里添加一个方法供外界调用,文件路径是node_modules/react-native-scrollable-tab-view/index.js
setNativeProps (scroll) {
//scroll为是否可以滑动的bool之
//scrollEnabled为源码中控制是否可以滑动的一个属性
        if(scroll){
            this.scrollView.setNativeProps({
                scrollEnabled: true,
            });
        } else {
            this.scrollView.setNativeProps({
                scrollEnabled: false,
            });
        }
 },
  1. ScrollableTabView绑定一个ref ref = "scrollTabView",通过这个调用我们刚才源码中添加的那个方法,通过传递一个bool来控制是否可以滑动从而实现lockSlideopenSlide两个方法
_lockSlide(){
        if (Platform.OS === 'android') {
            this.refs.scrollTabView.setNativeProps(false);
        }
    }

    _openSlide(){
        if (Platform.OS === 'android'){
            this.refs.scrollTabView.setNativeProps(true);
        }
    }
上一篇 下一篇

猜你喜欢

热点阅读