react-native 滑动标题栏

在我们的应用中经常有上面显示一行标题栏,下面分别每个标题对应一个页面,标题栏与页面联动的情形,在Android中我们可以简单用Toolbar和ViewPager来实现,react-native中至今还没有提供原生的组件供我们来应用,但我们可以通过依赖github大神skv-headless的react-native-scrollable-tab-view(https://github.com/skv-headless/react-native-scrollable-tab-view)来实现相应的功能。
首先我们还是要切换到我们的项目目录下,运行 npm install react-native-scrollable-tab-view –save,来将项目依赖进我们的项目中。
这里写图片描述
现在,我们就可以在我们的项目中使用。首先

import ScrollableTabView from 'react-native-scrollable-tab-view';

再将ScrollableTabView组件添加进我们的代码中:

<ScrollableTabView
                        renderTabBar={()=><CustomTabBar/>}
                        style={{flex:1,backgroundColor:'white'}}
                        tabBarBackgroundColor="white"
                        tabBarInactiveTextColor="#494949"
                        tabBarActiveTextColor="#00A9F2"
                        tabBarUnderlineStyle={{backgroundColor:'#00A9F2'}}
                    >
                        <FindList tabLabel="精选"/>
                        <FindList tabLabel="同城"/>
                        <FindList tabLabel="资讯"/>
                        <FindList tabLabel="活动"/>
                        <FindList tabLabel="话题"/>
                    </ScrollableTabView>
  • renderTabBar 可以指定我们自定义TabBar组件
  • tabBarBackgroundColor tabBar背景的颜色
  • tabBarInactiveTextColor tab没有被选中时的字体颜色
  • tabBarActiveTextColor tab被选中时的字体颜色
  • tabBarUnderlineStyle 定义下划线的样式
  • tabBarTextStyle 设置tab文本的样式 例:{fontFamily: ‘Roboto’, fontSize: 15}
  • initialPage number 设置初始选中的page

FindList是对应滑动的页面,tabLabel即为该页面对应的tab文本值。

截图:
这里写图片描述

源码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值