React Native 使用 React-native-scrollable-tab-view 实现 类头条 新闻页效果

效果如下:

一、安装依赖

npm install react-native-scrollable-tab-view --save

安装后对应版本依赖如下:

"dependencies": {
"react": "16.8.3",
"react-native": "0.59.5",
"react-native-scrollable-tab-view": "^0.10.0",
},

二、实现代码

1)显示View代码

import React, {Component} from 'react';
import {Text, View} from 'react-native'; import styles from '../../style/NewsStyle';
import ScrollableTabView, {DefaultTabBar, ScrollableTabBar} from 'react-native-scrollable-tab-view'; /**
* 新闻主页
*/
class News extends Component { render() {
return (
<ScrollableTabView
tabBarPosition='top' //位于屏幕的位置,top顶部 bottom底部 overlayTop顶部,悬浮在内容视图之上 overlayBottom底部,悬浮在内容视图之上
locked={false} //表示手指是否能拖动视图,默认为false(表示可以拖动)
scrollWithoutAnimation={true} //视图切换是否有动画
style={styles.container}
renderTabBar={() => <ScrollableTabBar />} //ScrollableTabBar支持超过屏幕宽度,Tab左右滚动,而DefaultTabBar不支持
onChangeTab={(obj) => {
console.log('index:' + obj.i);
}}
tabBarUnderlineStyle={styles.lineStyle}
tabBarActiveTextColor='#FF0000'
> <Text style={styles.textStyle} tabLabel='娱乐'>娱乐1</Text>
<Text style={styles.textStyle} tabLabel='科技'>科技1</Text>
<Text style={styles.textStyle} tabLabel='军事'>军事1</Text>
<Text style={styles.textStyle} tabLabel='体育'>体育1</Text>
<Text style={styles.textStyle} tabLabel='娱乐'>娱乐1</Text>
<Text style={styles.textStyle} tabLabel='科技'>科技1</Text>
<Text style={styles.textStyle} tabLabel='军事'>军事1</Text>
<Text style={styles.textStyle} tabLabel='体育'>体育1</Text>
<Text style={styles.textStyle} tabLabel='娱乐'>娱乐1</Text>
<Text style={styles.textStyle} tabLabel='科技'>科技1</Text>
<Text style={styles.textStyle} tabLabel='军事'>军事1</Text>
<Text style={styles.textStyle} tabLabel='体育'>体育1</Text> </ScrollableTabView>
);
}
} module.exports = News;

2)样式Style文件

NewsStyle.js

/**
* 新闻主页样式
*/
import {StyleSheet} from 'react-native'; export const styles = StyleSheet.create({
container: {
flex: 1,
marginTop: -4,
},
lineStyle: {
height: 1,
backgroundColor: '#FF0000',
},
textStyle: {
flex: 1,
fontSize: 16,
marginTop: 20,
textAlign: 'center',
},
}); module.exports = styles;

本博客地址: wukong1688

本文原文地址:https://www.cnblogs.com/wukong1688/p/10832079.html

转载请著名出处!谢谢~~

[RN] React Native 使用 React-native-scrollable-tab-view 实现 类头条 新闻页头部 效果的更多相关文章

  1. 【React Native】React Native项目设计与知识点分享

    闲暇之余,写了一个React Native的demo,可以作为大家的入门学习参考. GitHub:https://github.com/xujianfu/ElmApp.git GitHub:https ...

  2. Native VS React Native VS 微信小程序

    随着React Native和 微信小程序的出现,Native一家独大的局面出现裂痕,很多小公司使用已经正在着手微信小程序和React Native了,我公司就已经走上React Native之路.那 ...

  3. React Native 开发之 (07) 常用组件-View

    掌握了React Native的组件就可以使用IOS的原生组件和API. 一 View组件 就像开发web应用程序中,需要使用很多的HTML标签.例如 div,form.但是在基于DIV+CSS布局的 ...

  4. React Native & react-native-web-player & React Native for Web

    React Native & react-native-web-player & React Native for Web https://github.com/dabbott/rea ...

  5. React Native之React速学教程(下)

    概述 本篇为<React Native之React速学教程>的最后一篇.本篇将带着大家一起认识ES6,学习在开发中常用的一些ES6的新特性,以及ES6与ES5的区别,解决大家在学习Reac ...

  6. React Native之React速学教程(中)

    概述 本篇为<React Native之React速学教程>的第一篇.本篇将从React的特点.如何使用React.JSX语法.组件(Component)以及组件的属性,状态等方面进行讲解 ...

  7. React Native之React速学教程(上)

    概述 本篇为<React Native之React速学教程>的第一篇.本篇将从React的特点.如何使用React.JSX语法.组件(Component)以及组件的属性,状态等方面进行讲解 ...

  8. WHAT IS THE DIFFERENCE BETWEEN REACT.JS AND REACT NATIVE?

    Amit Ashwini - 09 SEPTEMBER 2017 React.js was developed by Facebook to address its need for a dynami ...

  9. react系列从零开始-react介绍

    react算是目前最火的js MVC框架了,写一个react系列的博客,顺便回忆一下react的基础知识,新入门前端的小白,可以持续关注,我会从零开始教大家用react开发一个完整的项目,也会涉及到w ...

随机推荐

  1. git学习笔记 ---添加远程库

    现在的情景是,你已经在本地创建了一个Git仓库后,又想在GitHub创建一个Git仓库,并且让这两个仓库进行远程同步,这样,GitHub上的仓库既可以作为备份,又可以让其他人通过该仓库来协作,真是一举 ...

  2. Go defer 会有性能损耗,尽量不要用?

    上个月在 @polaris @轩脉刃 的全栈技术群里看到一个小伙伴问 “说 defer 在栈退出时执行,会有性能损耗,尽量不要用,这个怎么解?”. 恰好前段时间写了一篇 <深入理解 Go def ...

  3. Git for Windows. 国内镜像

    感谢https://github.com/waylau/git-for-win Git for Windows. 国内直接从官网(http://git-scm.com/download/win)下载比 ...

  4. Python进阶(八)----模块,import , from import 和 `__name__`的使用

    Python进阶(八)----模块,import , from import 和 __name__的使用 一丶模块的初识 #### 什么是模块: # 模块就是一个py文件(这个模块存放很多相似的功能, ...

  5. Linux负载模拟

    转载:https://blog.csdn.net/F8qG7f9YD02Pe/article/details/79063392 CPU 下面命令会创建 CPU 负荷,方法是通过压缩随机数据并将结果发送 ...

  6. scrapy 管道里面使用mysql插入数据库

    # -*- coding: utf-8 -*- # Define your item pipelines here # # Don't forget to add your pipeline to t ...

  7. vue echarts中绑定的click函数无法引用vue实例data里面的数据

    在使用echarts的时候,需要在触发click事件之后去修改实例data里面的数据,可是发现用this引用后总是出现undefined, 解决办法: myChart.on('click', (par ...

  8. Jenkins使用过程中注意事项

    jenkins自动部署注意事项: 安装jenkins https://blog.csdn.net/qq_37372007/article/details/81586751 1.当提示错误ERROR: ...

  9. java requestmapping中关于路径的问题

    需要这种url写的方式才能映射

  10. GROUP BY HAVING,ORDER BY

    --HAVING语句与GROUP BY语句联合使用,用来过滤由GROUP BY语句返回的记录集. --并且HAVING语句的存在弥补了WHERE关键字不能与聚合函数联合使用的不足. ), SUM([C ...