美文网首页
react-native-swiper解决无法竖屏以及禁用滚动

react-native-swiper解决无法竖屏以及禁用滚动

作者: 张大娃创业笔记 | 来源:发表于2019-05-06 18:27 被阅读0次

一、无法竖屏

react-native-swiper 1.5.14版本无法竖屏滚动,需要切换到1.5.13版本就能正常切换,或者执行下面命令安装另一个库:(其实这个库也是1.5.13)

npm i @nart/react-native-swiper --save
import Swiper from '@nart/react-native-swiper'

二、禁用垂直滚动无效

得去修改node_model里的组件了,就是插件源代码,这里首先修改react-native-swiper/src/index.js:

 static propTypes = {
    .......
    scrollEnabled: PropTypes.bool,//此处加入禁止滑动属性
    .......
  }

再修改垂直滑动用到的组件:react-native-vertical-view-pager/src/component/index.js:

 <ScrollView
       {...this.props}
       ref={scrollview => this._refScrollView(scrollview)}
       onLayout={e => this._onLayout(e)}
       horizontal={false}
       style={style}
       // scrollEnabled={this.state.scrollEnabled}//此处去除它本身一直保持滑动状态
       onScrollBeginDrag={e => this.onScrollBeginDrag(e)}
       onScrollEndDrag={e => this.onScrollEndDrag(e)}
       onMomentumScrollEnd={e => this.onMomentumScrollEnd(e)}
       onScroll={e => this.onScroll(e)}
      scrollEventThrottle={50}
      contentContainerStyle={contentContainerStyle}>
       {this.props.children}
 </ScrollView>

相关文章

网友评论

      本文标题:react-native-swiper解决无法竖屏以及禁用滚动

      本文链接:https://www.haomeiwen.com/subject/bkidoqtx.html