react-native底部导航栏实现
- react-native-tab-navigator实现:
bottom.js代码如下:
import React, {Component} from 'react';
import {StyleSheet, View,Text,Image} from 'react-native';
import TabNavigator from 'react-native-tab-navigator'
export default class Bottom extends Component {
/*初始化state*/
constructor(props){
super();
this.state={
selectedTab:'tb_msg',
}
}
/**
* 公共组件方法
* @param selectedTab 选中的tab
* @param title
* @param icon
* @param selectedIcon
* @param imageStyle 选中时渲染图标的颜色
* @param mark 角标
* @param viewContent 页面内容
* @returns {*}
*/
tabNavigatorItems(selectedTab,title,icon,selectedIcon,imageStyle,mark,viewContent){
return (
<TabNavigator.Item
selected={this.state.selectedTab === selectedTab }
title={title}
renderIcon={()=> <Image style={styles.myImage} source={icon}/> }
renderSelectedIcon={()=> <Image style={[styles.myImage,{tintColor:imageStyle}]} source={selectedIcon}/> }
badgeText={mark}
onPress={()=> this.setState({selectedTab:selectedTab}) }>
<View style={{flex:1}}><Text>{viewContent}</Text></View>
</TabNavigator.Item>
)
}
render() {
return (
<View style={styles.container}>
<TabNavigator>
{this.tabNavigatorItems('tb_msg',"消息",require('../../assets/img/zhuye.png'),require("../../assets/img/zhuyesl.png"),'#622193',"","消息页面内容")}
{this.tabNavigatorItems('tb_contacts',"联系人",require('../../assets/img/zhuye.png'),require("../../assets/img/zhuye.png"),'#65bb74',"","联系人页面内容")}
{this.tabNavigatorItems('tb_watch',"看点",require('../../assets/img/zhuye.png'),require("../../assets/img/zhuye.png"),'#6ebef3',"","看点页面内容")}
{this.tabNavigatorItems('tb_dynamic',"动态",require('../../assets/img/zhuye.png'),require("../../assets/img/zhuye.png"),'#622193',"","动态页面内容")}
</TabNavigator>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F5FCFF',
},
myImage:{
width:22,
height:22,
}
});
运行:react-native run-android

运行结果:

方法二:
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View,
Image
} from 'react-native';
import TabNavigator from 'react-native-tab-navigator';
import Home from './component/bottom/home';
import Article from './component/bottom/article';
import Order from './component/bottom/order';
import Owner from './component/bottom/owner';
const dataSource = [
{icon:require('./assets/img/zhuye.png'),selectedIcon:require('./assets/img/zhuyesl.png'),tabPage:'Home',tabName:'首页',component:Home},
{icon:require('./assets/img/zhuye.png'),selectedIcon:require('./assets/img/zhuyesl.png'),tabPage:'Article',tabName:'文章',component:Article},
{icon:require('./assets/img/zhuye.png'),selectedIcon:require('./assets/img/zhuyesl.png'),tabPage:'Order',tabName:'订单',component:Order},
{icon:require('./assets/img/zhuye.png'),selectedIcon:require('./assets/img/zhuyesl.png'),tabPage:'Owner',tabName:'我的',component:Owner}
]
var navigation = null;
type Props = {};
export default class App extends Component<Props> {
constructor(props){
super(props);
navigation = this.props.navigation;
this.state = {
selectedTab:'Home'
}
}
render() {
let tabViews = dataSource.map((item,i) => {
return (
<TabNavigator.Item
title={item.tabName}
selected={this.state.selectedTab===item.tabPage}
titleStyle={{color:'black'}}
selectedTitleStyle={{color:'#7A16BD'}}
renderIcon={()=><Image style={styles.tabIcon} source={item.icon}/>}
renderSelectedIcon = {() => <Image style={styles.tabIcon} source={item.selectedIcon}/>}
tabStyle={{alignSelf:'center'}}
onPress = {() => {this.setState({selectedTab:item.tabPage})}}
key={i}
>
<item.component navigation={navigation}/>
</TabNavigator.Item>
);
})
return (
<View style={styles.container}>
<TabNavigator
hidesTabTouch={true}
>
{tabViews}
</TabNavigator>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F5FCFF',
},
tabIcon:{
width:23,
height:23,
}
});
出现问题1:
黄色警告
解决方法:
index.js文件中,放在AppRegistry.registerComponent('App', () => App)之前即可
console.ignoredYellowBox = ['Warning: BackAndroid is deprecated. Please use BackHandler instead.','source.uri should not be an empty string','Invalid props.style key'];
console.disableYellowBox = true // 关闭全部黄色警告
react-native底部导航栏实现的更多相关文章
- React Native 底部导航栏
首先安装:npm install react-native-tab-navigator 然后再引入文件中 import TabNavigator from 'react-native-tab ...
- [RN] React Native 自定义导航栏随滚动渐变
React Native 自定义导航栏随滚动渐变 实现效果预览: 代码实现: 1.定义导航栏 NavPage.js import React, {Component} from 'react'; im ...
- React Native自定义导航栏
之前我们学习了可触摸组件和页面导航的使用的使用: 从零学React Native之09可触摸组件 - 从零学React Native之03页面导航 - 经过之前的学习, 我们可以完成一个自定义导航栏了 ...
- react native底部tab栏切换
1.安装tab栏插件 npm i react-native-tab-navigator --save 2.引入对应的组件和tab插件 import { Platform, StyleSheet, Te ...
- React Native 之导航栏
一定要参考官网: https://reactnavigation.org/docs/en/getting-started.html 代码来自慕课网:https://www.imooc.com/cour ...
- React Native(四)——顶部以及底部导航栏实现方式
效果图: 一步一步慢慢来: 其实刚入手做app的时候,就应该做出简单的顶部以及底部导航栏.无奈又在忙其他事情,导致这些现在才整理出来. 1.顶部导航栏:react-native-scrollable- ...
- React-native 底部导航栏(二)
1.组件安装:npm install react-native-router-flux --save 2.定义菜单图片和文字: import React, { Component } from 're ...
- TextView+Fragment实现底部导航栏
前言:项目第二版刚上线没多久,产品又对需求进行了大改动,以前用的是左滑菜单,现在又要换成底部导航栏,于是今天又苦逼加班了.花了几个小时实现了一个底部导航栏的demo,然后总结一下.写一篇博客.供自己以 ...
- Android应用底部导航栏(选项卡)实例
现在很多android的应用都采用底部导航栏的功能,这样可以使得用户在使用过程中随意切换不同的页面,现在我采用TabHost组件来自定义一个底部的导航栏的功能. 我们先看下该demo实例的框架图: 其 ...
- Android 修改底部导航栏navigationbar的颜色
Android 修改底部导航栏navigationbar的颜色 getWindow().setNavigationBarColor(Color.BLUE); //写法一 getWindow().set ...
随机推荐
- iOS13即将到来,iOS推送Device Token适配方案详解
关于提前适配iOS13 苹果推送DeviceToken的通知 随着苹果iOS13系统即将发布,个推提前推出DeviceToken适配方案,以确保新版本的兼容与APP推送服务的正常使用.iOS13的一个 ...
- better-scroll 滑动插件的使用
better-scroll 滑动插件的使用 拥有的效果:下拉刷新.上拉加载.滑动.轮播
- Kotlin 1 新运算符
新运算符: “..” ,"in ","!in" ,"downto","step"注意: 1. 关系运算符的优先级低于算术 ...
- P1533可怜的狗狗
困死了,完全做不下去题 就当是对莫队最最基本的思想的一个复习叭(只有最最基本的思想,没有莫队) 传送 我们可以很容易的想到这题要用线段树. 60pts 此题要求某个区间里第K小的数,可以暴力的考虑对每 ...
- IMDB Classification on Keras
IMDB Classification on Keras In the book of Deep Learning with Python, there is an example of IMDB m ...
- leetcode 121买卖股票的最佳时机I
从下标1开始,维护两个变量,一个是0~i-1中的最低价格low,一个是当前的最高利润res;先更新最高利润,在更新最低价格:应用了贪心算法的基本思想,总是选择买入价格最低的股票,代码如下: 具有最优子 ...
- 什么是IntentService?有何优点?
一.IntentService 简介 IntentService 是 Service 的子类,比普通的 Service 增加了额外的功能.先看 Service 本身存在两个问题:Service 不会专 ...
- Vs code工具汉化
官网为:https://code.visualstudio.com/ 看到中间有一些提示的命令 选择第一条,即Ctrl+shift+P,弹出命令行,选择"Configure Display ...
- oracle 一张表插入另外一张表 存储过程
----创建存储过程 create or replace procedure inserttest as cursor cs is select id, name, cla, addr, phone, ...
- UML学习笔记_01_基本概念
1.什么是UML Unified Modeling Language (UML)又称统一建模语言或标准建模语言,是始于1997年一个OMG标准,它是一个支持模型化和软件系统开发的图形化语言,为软件开发 ...