react native中使用ScrollableTabView
第一步,下载依赖
npm install react-native-scrollable-tab-view --save
第二步,引入
import ScrollableTabView, { ScrollableTabBar, DefaultTabBar } from 'react-native-scrollable-tab-view';
第三步,使用
class TabTopView extends Component {
render() {
return (
<ScrollableTabView
style={styles.container}
renderTabBar={() => <DefaultTabBar />}
tabBarUnderlineStyle={styles.lineStyle}
tabBarActiveTextColor='#FF0000'>
<Text style={styles.textStyle} tabLabel='娱乐'>娱乐</Text>
<Text style={styles.textStyle} tabLabel='科技'>科技</Text>
<Text style={styles.textStyle} tabLabel='军事'>军事</Text>
<Text style={styles.textStyle} tabLabel='体育'>体育</Text>
</ScrollableTabView>
);
}
由于我把里面的一层提出来循环了,所以在上面使用方法的时候直接找了另一种方法
效果图是

完整代码是 home.js
import React, { Component } from 'react';
import { StyleSheet,View,Text,Dimensions } from 'react-native';
import ScrollableTabView, { ScrollableTabBar, DefaultTabBar } from 'react-native-scrollable-tab-view';
// 取得屏幕的宽高Dimensions
const { width, height } = Dimensions.get('window');
export default class App extends Component{
constructor(props) {
super(props);
this.state = {
tabShow: false,
label: ['推荐', '新品', '居家', '餐厨', '配件', '服装', '电器', '洗护', '杂货', '饮食', '婴童', '志趣'],
};
}
componentDidMount() {
setTimeout(() => {
this.setState({
tabShow: true
});
}, 0)
}
// 滑动tab
renderScrollableTab() {
let label = this.state.label
if (this.state.tabShow){
return (
<ScrollableTabView
renderTabBar={() => <ScrollableTabBar />}
tabBarBackgroundColor='#ddd'
tabBarActiveTextColor='#b4282d'
tabBarInactiveTextColor='#333'
tabBarUnderlineStyle={styles.tabBarUnderline}
>
{
label.map((item, index) => {
if (item == '推荐') {
return (
<Text tabLabel={item} key={index}>推荐</Text>
)
} else {
return (
<Text tabLabel={item} key={index}>其他页面</Text>
)
}
})
}
</ScrollableTabView>
)
}
}
render(){
return(
<View style={styles.container}>
<View style={{ flex: 1 }}>
{this.renderScrollableTab()}
</View>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
backgroundColor: '#efefef',
},
navLeft: {
alignItems: 'center',
marginLeft: 10,
},
navRight: {
alignItems: 'center',
marginRight: 10,
},
navIcon: {
height: 20,
width: 20,
},
navText: {
fontSize: 10,
},
searchBox: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
width: width * 0.7,
backgroundColor: '#ededed',
borderRadius: 5,
height: 30,
},
searchIcon: {
width: 16,
height: 16,
marginRight: 6,
},
searchContent: {
color: '#666',
fontSize: 14,
},
tabBarUnderline: {
backgroundColor: '#b4282d',
height: 2,
}
});
react native中使用ScrollableTabView的更多相关文章
- [RN] React Native中使用 react-native-scrollable-tab-view嵌套在ScrollView里,导致 子内容 在安卓上无法显示
React Native中使用 react-native-scrollable-tab-view嵌套在ScrollView里,导致 子内容 在安卓上无法显示 问题: 0.9.0 或 0.8.0 版本的 ...
- React Native 中 CSS 的使用
首先声明,此文原作者为黎 跃春 React Native中CSS 内联样式 对象样式 使用Stylesheet.Create 样式拼接 导出样式对象 下面的代码是index.ios.js中的代码: / ...
- react native中的欢迎页(解决首加载白屏)
参照网页: http://blog.csdn.net/fengyuzhengfan/article/details/52712829 首先是在原生中写一些方法,然后通过react native中js去 ...
- React Native中的网络请求fetch和简单封装
React Native中的网络请求fetch使用方法最为简单,但却可以实现大多数的网络请求,需要了解更多的可以访问: https://segmentfault.com/a/1190000003810 ...
- [转] 「指尖上的魔法」 - 谈谈 React Native 中的手势
http://gold.xitu.io/entry/55fa202960b28497519db23f React-Native是一款由Facebook开发并开源的框架,主要卖点是使用JavaScrip ...
- [转] 在React Native中使用ART
http://bbs.reactnative.cn/topic/306/%E5%9C%A8react-native%E4%B8%AD%E4%BD%BF%E7%94%A8art 前半个月捣腾了一下Rea ...
- react native中使用echarts
开发平台:mac pro node版本:v8.11.2 npm版本:6.4.1 react-native版本:0.57.8 native-echarts版本:^0.5.0 目标平台:android端收 ...
- react native中一次错误排查 Error:Error: Duplicate resources
最近一直在使用react native中,遇到了很多的坑,同时也学习到了一些移动端的开发经验. 今天在做一个打包的测试时,遇到了一个问题,打包过程中报错“Error:Error: Duplicate ...
- 在React Native中,使用fetch网络请求 实现get 和 post
//在React Native中,使用fetch实现网络请求 /* fetch 是一个封装程度更高的网络API, 使用了Promise * Promise 是异步编程的一种解决方案 * Promise ...
随机推荐
- hive优化之并行执行任务
1.与Oracle并行技术一样,hive在执行mapreduce作业时也可以执行并行查询.针对于不同业务场景SQL语句的执行情况,有些场景下SQL的执行是需要分割成几段去执行的,而且期间并不全是存在依 ...
- CentOS 7 升级内核
升级 CentOS 内核参考资料 1 升级 CentOS 内核参考资料 2 通过 /proc 虚拟文件系统读取或配置内核 Linux 内核官网 CentOS 官网 1. 关于 Linux 内核 Lin ...
- LU decomposition can be viewed as the matrix form of Gaussian elimination.
https://en.wikipedia.org/wiki/LU_decomposition One way to find the LU decomposition of this simple m ...
- 将获得datebox值的文本形式转为日期格式
在使用datebox时,已选择结束日期后,再次选择开始日期.此时判断开始日期不能大于结束日期. datebox的onSelect: function (date){}事件传入的参数是日期类型,而使用d ...
- LeetCode 961 N-Repeated Element in Size 2N Array 解题报告
题目要求 In a array A of size 2N, there are N+1 unique elements, and exactly one of these elements is re ...
- vue安装调试器Vue.js devtools
一. 打开https://github.com/vuejs/vue-devtools,进入gitlab.往下翻找到: 找到installation,选择以chrome的拓展方式安装. 二. 这边选择添 ...
- eclipse背景色设置成护眼色(豆沙绿)
1.点击windows -->preferences 2.展开Editors 3.选择自定义颜色 4.把色调调成:85 饱和度调成:123 亮度调成205 即可调成豆沙绿色了 然后点确定.
- 1-2-编译U-boot
1-2-编译U-boot 1.su+enter进入超级用户模式. 2.cd /mnt/+两次Tab去到根目录,ls显示共享文件夹里的文件. 3.解压tar xvfj uboot_TQ210_1.3.4 ...
- cors与jsonp
在.net中,可以在webApiConfig代码里写,也可以在web.config里配置,但都需要引入System.Web.Cors.这些都是服务器端的配置,对整个项目有效. {若只想对某个请求有效, ...
- 如何为DigitalOcean上的服务器配置SSH密钥
本指南适用于mac OS和Linux,windows用户请绕道. 通常,当你启动DigitalOcean droplets时,只要过程完成,你会收到一封电子邮件,让你知道droplets的IP地址和密 ...