react-native实践日记--6.ReactNative 项目版本升级,0.61到0.72升级的问题记录(二)

接上一篇,ReactNative项目升级,0.61到0.72的升级问题。
在升级过程中,发现react-native-scrollable-tab-view这个tab插件,这是一个tab导航栏插件,可以实现切换页面、页面滚动、下拉刷新、上拉加载更多等,功能还是很强大的,只是官方的版本已经很久没更新了,无法兼容react-native@0.72,但一时又找不到更好的插件代替,只能先试着改下源码兼容下新版本。还好在github上已经有人提出解决方案了,找出问题代码,改一下就好了。

四、tab插件:react-native-scrollable-tab-view

由于GitHub上已经做了部分兼容修改,故更改package.json中的依赖地址:“react-native-scrollable-tab-view”: “https://github.com/ptomasroos/react-native-scrollable-tab-view”,并修改部分源码;

//ScrollableTabBar.js,找到ref={'tabContainer'}并注释掉
<View
          style={[styles.tabs, {width: this.state._containerWidth, }, this.props.tabsContainerStyle, ]}
          // ref={'tabContainer'}
          onLayout={this.onTabContainerLayout}
        >
          {this.props.tabs.map((name, page) => {
            const isTabActive = this.props.activeTab === page;
            const renderTab = this.props.renderTab || this.renderTab;
            return renderTab(name, page, isTabActive, this.props.goToPage, this.measureTab.bind(this, page));
          })}
          <Animated.View style={[tabUnderlineStyle, dynamicTabUnderline, this.props.underlineStyle, ]} />
</View>


//ViewPager.js修改VIEW_PAGER_REF相关的两处:ref={VIEW_PAGER_REF}和this.$refs[VIEW_PAGER_REF].getInnerViewNode()

getInnerViewNode = (): ReactComponent => {
    return this.pageView.getInnerViewNode();
};
render() {
    return (
      <NativeViewPager
        {...this.props}
        ref={pageView => (this.pageView = pageView)}
        style={this.props.style}
        onPageScroll={this._onPageScroll}
        onPageScrollStateChanged={this._onPageScrollStateChanged}
        onPageSelected={this._onPageSelected}
        onMoveShouldSetResponderCapture={this._onMoveShouldSetResponderCapture}
        children={childrenWithOverriddenStyle(this.props.children)}
      />
    );
  }


//DefaultTabBar.js、index.js、ScrollableTabBar.js
//找出下面的这个引用,
const { ViewPropTypes } = ReactNative = require('react-native');
//改成如下引用:
const ReactNative = require('react-native');
const DeprecatedPropTypes = require('deprecated-react-native-prop-types');
//将页面中用到ViewPropTypes的改为DeprecatedPropTypes相关


/*** DefaultTabBar.js ***/
propTypes: {
    goToPage: PropTypes.func,
    activeTab: PropTypes.number,
    tabs: PropTypes.array,
    backgroundColor: PropTypes.string,
    activeTextColor: PropTypes.string,
    inactiveTextColor: PropTypes.string,
    textStyle: DeprecatedPropTypes.TextPropTypes.style,
    tabStyle: DeprecatedPropTypes.ViewPropTypes.style,
    renderTab: PropTypes.func,
    underlineStyle: DeprecatedPropTypes.ViewPropTypes.style,
  },

/*** index.js ***/
propTypes: {
    tabBarPosition: PropTypes.oneOf(['top', 'bottom', 'overlayTop', 'overlayBottom', ]),
    initialPage: PropTypes.number,
    page: PropTypes.number,
    onChangeTab: PropTypes.func,
    onScroll: PropTypes.func,
    renderTabBar: PropTypes.any,
    tabBarUnderlineStyle: DeprecatedPropTypes.ViewPropTypes.style,
    tabBarBackgroundColor: PropTypes.string,
    tabBarActiveTextColor: PropTypes.string,
    tabBarInactiveTextColor: PropTypes.string,
    tabBarTextStyle: PropTypes.object,
    style: DeprecatedPropTypes.ViewPropTypes.style,
    contentProps: PropTypes.object,
    scrollWithoutAnimation: PropTypes.bool,
    locked: PropTypes.bool,
    prerenderingSiblingsNumber: PropTypes.number,
  },

/*** ScrollableTabBar.js ***/
propTypes: {
    goToPage: PropTypes.func,
    activeTab: PropTypes.number,
    tabs: PropTypes.array,
    backgroundColor: PropTypes.string,
    activeTextColor: PropTypes.string,
    inactiveTextColor: PropTypes.string,
    scrollOffset: PropTypes.number,
    style: DeprecatedPropTypes.ViewPropTypes.style,
    tabStyle: DeprecatedPropTypes.ViewPropTypes.style,
    tabsContainerStyle: DeprecatedPropTypes.ViewPropTypes.style,
    textStyle: DeprecatedPropTypes.TextPropTypes.style,
    renderTab: PropTypes.func,
    underlineStyle: DeprecatedPropTypes.ViewPropTypes.style,
    onScroll: PropTypes.func,
  }


  • 14
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

戴花环的蜗牛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值