第一步,下载依赖

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. POJ 1179 - Polygon - [区间DP]

    题目链接:http://poj.org/problem?id=1179 Time Limit: 1000MS Memory Limit: 10000K Description Polygon is a ...

  2. shell脚本之xargs使用的一些案例

    首先看一下文本信息: # cat text1.txt 1 2 3 4 5 使用xargs格式化一下: # cat text1.txt  | xargs 1 2 3 4 5 使用xargs格式化,每两个 ...

  3. [qemu][kvm] 在一个vmware虚拟机里安装qemu-kvm虚拟机

    说起来这个需求,简直是傻傻的.但却实实在在的摆在我的面前.... VM无外乎就是为了模拟场景:我现在要的场景就是一台很多个core的linux主机.但是我只有一个装了windows的笔记本.上边有一个 ...

  4. 树和二叉树->存储结构

    文字描述 1 二叉树的顺序存储 用一组地址连续的存储单元自上而下,自左至右存储完全二叉树上的结点元素. 这种顺序存储只适用于完全二叉树.因为,在最坏情况下,一个深度为k且只有k个结点的单支树却需要长度 ...

  5. Django 正向解析与反向解析

    正向解析就是按照顺序查找访问(urls.py---view--templates) 反向解析就是根据命名空间命名来调到指定的页面 用反向解析的原因: 随着功能的增加会出现更多的视图,可能之前配置的正则 ...

  6. python武器库

    1,开发库You-GetYouTube/Youku/Niconico视频下载器Zipline一个Pythonic的交易算法库docopt为Python程序创造一个优雅的命令行界面PDFMinerPyt ...

  7. dispatch_queue_set_specific可重入的gcd

    有时候我们很希望知道当前执行的queue是谁,比如UI操作需要放在main queue中执行.如果可以知道当前工作的queue是谁,就可以很方便的指定一段代码操作在特定的queue中执行.这种做法让G ...

  8. svn 客户端安装 windows

    windows使用的 https://tortoisesvn.net/ 下载中文语言包 安装 安装完安装语言包 看到这个代表svn客户端可以用了 windows客户端下载TortoiseSVN软件进行 ...

  9. nessus的安装

    nessus安装 .下载地址 http://www.tenable.com/products/nessus/select-your-operating-system .获取注册码 www.nessus ...

  10. pt-table-checksum 使用实践

    在另外部署的机器上执行:      pt-table-checksum h='192.168.122.47',u='root',p='cc.123',P=3306 -d cat --nocheck-r ...