1.Main.js

/**
* 主页面
*/
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View,
Image,
Platform, //判断当前运行的系统
} from 'react-native'; /*=============导入外部组件类==============*/
import TabNavigator from 'react-native-tab-navigator';
import CustomerComponents, { Navigator } from 'react-native-deprecated-custom-components'; // 引入外部的组件(此处注意是相当于了项目根目录)
var Home = require('../Component/Home');
var Message = require('../Component/Message');
var Find = require('../Component/Find');
var Mine = require('../Component/Mine'); // ES5
var Main = React.createClass({
// 初始化函数(变量是可以改变的,充当状态机的角色)
getInitialState(){
return{
selectedTab:'home' // 默认选中的tabBar
}
}, render() {
return (
<TabNavigator>
{/*--首页--*/}
{this.renderTabBarItem('首页','icon_tabbar_home','icon_tabbar_home_selected','home','首页',Home,1)}
{/*--消息--*/}
{this.renderTabBarItem('消息','icon_tabbar_message','icon_tabbar_message_selected','message','消息',Message,2)}
{/*--发现--*/}
{this.renderTabBarItem('发现','icon_tabbar_find','icon_tabbar_find_selected','find','发现',Find)}
{/*--我的--*/}
{this.renderTabBarItem('我的','icon_tabbar_mine','icon_tabbar_mine_selected','mine','我的',Mine)}
</TabNavigator>
);
}, // 封装tabBarItem
renderTabBarItem(title,iconName,selectedIconName,selectedTab,componentName,component,badgeText){
return(
<TabNavigator.Item
title={title}
renderIcon={() => <Image source={{uri:iconName}} style={styles.iconStyle} />}
renderSelectedIcon={() => <Image source={{uri:selectedIconName}} style={styles.iconStyle} />}
selected={this.state.selectedTab === selectedTab}
onPress={() => this.setState({ selectedTab: selectedTab })}
selectedTitleStyle={styles.selectedTitleStyle} //tabBarItem选中的文字样式
badgeText={badgeText}
>
<Navigator
initialRoute={{name: componentName, component:component}}
configureScene={()=>{
return Navigator.SceneConfigs.PushFromRight;
}}
renderScene={(route, navigator) =>{
let Component = route.component;
return <Component {...route.passProps} navigator={navigator} />
}}
/>
</TabNavigator.Item>
)
}
}); const styles = StyleSheet.create({
// icon默认样式
iconStyle:{
width: Platform.OS === 'ios' ? 30 : 25,
height:Platform.OS === 'ios' ? 30 : 25,
},
// tabBarItem选中的文字样式
selectedTitleStyle:{
color: 'rgba(212,97,0,1)',
}
}); // 输出
module.exports = Main;

简化代码

2.Home.js

/**
* 首页
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Image,
TouchableOpacity,
Platform
} from 'react-native'; var Home = React.createClass({
render() {
return (
<View style={styles.container}>
{/*导航条*/}
{this.renderNavBar()}
<Text style={styles.welcome}>
首页
</Text>
</View>
);
},
// 导航条
renderNavBar(){
return(
<View style={styles.navOutViewStyle}>
<Text style={{color:'white',fontSize:16,fontWeight:'bold'}}>首页</Text>
</View>
)
}
}); const styles = StyleSheet.create({
// 导航条视图
navOutViewStyle:{
height:Platform.OS === 'ios' ? 64 : 44,
backgroundColor:'#468AFF',
// 主轴方向
flexDirection:'row',
// 侧轴对齐方式 垂直居中
alignItems:'center',
// 主轴方向居中
justifyContent:'center',
},
container: {
flex: 1,
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
}); // 输出类
module.exports = Home;

3.Message.js

/**
* 消息
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Image,
TouchableOpacity,
Platform
} from 'react-native'; var Message = React.createClass({
render() {
return (
<View style={styles.container}>
{/*导航条*/}
{this.renderNavBar()}
<Text style={styles.welcome}>
消息
</Text>
</View>
);
},
// 导航条
renderNavBar(){
return(
<View style={styles.navOutViewStyle}>
<Text style={{color:'white',fontSize:16,fontWeight:'bold'}}>消息</Text>
</View>
)
}
}); const styles = StyleSheet.create({
// 导航条视图
navOutViewStyle:{
height:Platform.OS === 'ios' ? 64 : 44,
backgroundColor:'#468AFF',
// 主轴方向
flexDirection:'row',
// 侧轴对齐方式 垂直居中
alignItems:'center',
// 主轴方向居中
justifyContent:'center',
},
container: {
flex: 1,
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
}); // 输出类
module.exports = Message;

4.Find.js

/**
* 发现
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Image,
TouchableOpacity,
Platform
} from 'react-native'; var Find = React.createClass({
render() {
return (
<View style={styles.container}>
{/*导航条*/}
{this.renderNavBar()}
<Text style={styles.welcome}>
发现
</Text>
</View>
);
},
// 导航条
renderNavBar(){
return(
<View style={styles.navOutViewStyle}>
<Text style={{color:'white',fontSize:16,fontWeight:'bold'}}>发现</Text>
</View>
)
}
}); const styles = StyleSheet.create({
// 导航条视图
navOutViewStyle:{
height:Platform.OS === 'ios' ? 64 : 44,
backgroundColor:'#468AFF',
// 主轴方向
flexDirection:'row',
// 侧轴对齐方式 垂直居中
alignItems:'center',
// 主轴方向居中
justifyContent:'center',
},
container: {
flex: 1,
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
}); // 输出类
module.exports = Find;

5.Mine.js

/**
* 我
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Image,
TouchableOpacity,
Platform
} from 'react-native'; var Mine = React.createClass({
render() {
return (
<View style={styles.container}>
{/*导航条*/}
{this.renderNavBar()}
<Text style={styles.welcome}>
我的
</Text>
</View>
);
},
// 导航条
renderNavBar(){
return(
<View style={styles.navOutViewStyle}>
<Text style={{color:'white',fontSize:16,fontWeight:'bold'}}>我的</Text>
</View>
)
}
}); const styles = StyleSheet.create({
// 导航条视图
navOutViewStyle:{
height:Platform.OS === 'ios' ? 64 : 44,
backgroundColor:'#468AFF',
// 主轴方向
flexDirection:'row',
// 侧轴对齐方式 垂直居中
alignItems:'center',
// 主轴方向居中
justifyContent:'center',
},
container: {
flex: 1,
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
}); // 输出类
module.exports = Mine;

6.效果图

最新文章

  1. 利用CSS3中transparent实现三角形及三角形组合图
  2. 将word文件快速转换成表格的技巧
  3. 第8章 用户模式下的线程同步(1)_Interlocked系列函数
  4. disconnected no supported authentication methods available(server sent: publickey,keyboard interae)
  5. 在MongoDB中实现聚合函数 (转)
  6. 二十四种设计模式:提供者模式(Provider Pattern)
  7. 可执行文件(ELF)格式之讲解
  8. SSH框架jar神包
  9. bzoj1816
  10. Web C# 导出Excel 方法总结
  11. http://codepen.io/zhou-yg/pen/NqgPmg 在线编辑器
  12. 2016腾讯&quot;创益24小时&quot;互联网公益创新大赛总结
  13. Java面试宝典
  14. 大区间素数筛选(POJ 2689)
  15. map用法
  16. 在CentOS上安装Python3的三种方法
  17. nodejs 开启http服务器
  18. HTML文本元素标签
  19. java死锁示例及其发现方法
  20. oracle 监听文件 说明

热门文章

  1. java集合之 ConcurrentHashMap的产生
  2. node.js使用express模块创建web服务器应用
  3. 封装运动框架基本函数(多个属性包括透明度和zIndex)
  4. iOS蓝牙中的进制转换,数据格式转换
  5. 进制转换以及byted与str的区别
  6. 021-Zabbix4.2对IIS监控摸索记录
  7. Big Data(二)分布式文件系统那么多,为什么hadoop还需要一个hdfs文件系统?
  8. Linux日常之命令sed
  9. urllib urllib2学习笔记
  10. BZOJ[3252]攻略(长链剖分)