第一步,下载依赖

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的更多相关文章

  1. [RN] React Native中使用 react-native-scrollable-tab-view嵌套在ScrollView里,导致 子内容 在安卓上无法显示

    React Native中使用 react-native-scrollable-tab-view嵌套在ScrollView里,导致 子内容 在安卓上无法显示 问题: 0.9.0 或 0.8.0 版本的 ...

  2. React Native 中 CSS 的使用

    首先声明,此文原作者为黎 跃春 React Native中CSS 内联样式 对象样式 使用Stylesheet.Create 样式拼接 导出样式对象 下面的代码是index.ios.js中的代码: / ...

  3. react native中的欢迎页(解决首加载白屏)

    参照网页: http://blog.csdn.net/fengyuzhengfan/article/details/52712829 首先是在原生中写一些方法,然后通过react native中js去 ...

  4. React Native中的网络请求fetch和简单封装

    React Native中的网络请求fetch使用方法最为简单,但却可以实现大多数的网络请求,需要了解更多的可以访问: https://segmentfault.com/a/1190000003810 ...

  5. [转] 「指尖上的魔法」 - 谈谈 React Native 中的手势

    http://gold.xitu.io/entry/55fa202960b28497519db23f React-Native是一款由Facebook开发并开源的框架,主要卖点是使用JavaScrip ...

  6. [转] 在React Native中使用ART

    http://bbs.reactnative.cn/topic/306/%E5%9C%A8react-native%E4%B8%AD%E4%BD%BF%E7%94%A8art 前半个月捣腾了一下Rea ...

  7. react native中使用echarts

    开发平台:mac pro node版本:v8.11.2 npm版本:6.4.1 react-native版本:0.57.8 native-echarts版本:^0.5.0 目标平台:android端收 ...

  8. react native中一次错误排查 Error:Error: Duplicate resources

    最近一直在使用react native中,遇到了很多的坑,同时也学习到了一些移动端的开发经验. 今天在做一个打包的测试时,遇到了一个问题,打包过程中报错“Error:Error: Duplicate ...

  9. 在React Native中,使用fetch网络请求 实现get 和 post

    //在React Native中,使用fetch实现网络请求 /* fetch 是一个封装程度更高的网络API, 使用了Promise * Promise 是异步编程的一种解决方案 * Promise ...

随机推荐

  1. CCPC-Wannafly Winter Camp Day3 Div1 - 排列

    题目链接:https://zhixincode.com/contest/14/problem/A?problem_id=203 time limit per test: 1 secondmemory ...

  2. [No0000159]C# 7 中的模范和实践

    关键点 遵循 .NET Framework 设计指南,时至今日,仍像十年前首次出版一样适用. API 设计至关重要,设计不当的API大大增加错误,同时降低可重用性. 始终保持"成功之道&qu ...

  3. [No0000151]菜鸟理解.NET Framework中的CLI,CLS,CTS,CLR,FCL,BCL

    最下层蓝色部分是.NET Framework的基础,也是所有应用软件的基础..NET Framework不是凭空出来的,实际上API,COM+,和一些相关驱动依然是它的基石..NET Framewor ...

  4. CSS3 ::selection 选择器

    ::selection { color:#ff0000; } ::-moz-selection { color:#ff0000; }详见 http://www.css88.com/archives/5 ...

  5. 2012年蓝桥杯省赛A组c++第3题(喝断片的海盗)

    /* 有一群海盗(不多于20人),在船上比拼酒量.过程如下:打开一瓶酒, 所有在场的人平分喝下,有几个人倒下了.再打开一瓶酒平分,又有倒下的, 再次重复...... 直到开了第4瓶酒,坐着的已经所剩无 ...

  6. 2017年蓝桥杯省赛A组c++第7题(正则问题)

    /* 描述:正则问题 考虑一种简单的正则表达式: 只由 x ( ) | 组成的正则表达式. 小明想求出这个正则表达式能接受的最长字符串的长度. 例如 ((xx|xxx)x|(x|xx))xx 能接受的 ...

  7. 模拟器运行报错:ld: symbol(s) not found for architecture x86_64

    模拟器运行报错: 报错信息如下: Undefined symbols for architecture x86_64: "_x264_encoder_open_142", refe ...

  8. 【Python爬虫】Requests库的基本使用

    Requests库的基本使用 阅读目录 基本的GET请求 带参数的GET请求 解析Json 获取二进制数据 添加headers 基本的POST请求 response属性 文件上传 获取cookie 会 ...

  9. 前端 HTML 常用标签 head标签相关内容 meta标签

    meta标签 Meta标签介绍: <meta>元素可提供有关页面的元信息(mata-information),针对搜索引擎和更新频度的描述和关键词. <meta>标签位于文档的 ...

  10. RN picker使用

    这里是只有苹果的,如果想适配andorid,可以在showPickerFun方法里面使用platefrom判断 代码: import React, {Component} from 'react'; ...