1.安装插件,cd到项目根目录下执行:

  1. $ npm i react-native-tab-navigator --save

2.主框架文件Main.js

  1. /**
  2. * 主页面
  3. */
  4. import React, { Component } from 'react';
  5. import {
  6. AppRegistry,
  7. StyleSheet,
  8. Text,
  9. View,
  10. Image,
  11. Platform //判断当前运行的系统
  12. } from 'react-native';
  13.  
  14. /*=============导入外部组件类==============*/
  15. import TabNavigator from 'react-native-tab-navigator';
  16. var Home = require('../Home/Home');
  17. var Shop = require('../Shop/Shop');
  18. var Mine = require('../Mine/Mine');
  19. var More = require('../More/More');
  20.  
  21. // ES5
  22. var Main = React.createClass({
  23. // 初始化函数(变量是可以改变的,充当状态机的角色)
  24. getInitialState(){
  25. return{
  26. selectedTab:'home' // 默认选中的tabBar
  27. }
  28. },
  29.  
  30. render() {
  31. return (
  32. <TabNavigator>
  33. {/*--首页--*/}
  34. <TabNavigator.Item
  35. title="首页"
  36. renderIcon={() => <Image source={{uri:'icon_tabbar_homepage'}} style={styles.iconStyle} />}
  37. renderSelectedIcon={() => <Image source={{uri:'icon_tabbar_homepage_selected'}} style={styles.selectedIconStyle} />}
  38. badgeText="1"
  39. selected={this.state.selectedTab === 'home'}
  40. onPress={() => this.setState({ selectedTab: 'home' })}
  41. >
  42. <Home />
  43. </TabNavigator.Item>
  44. {/*--商家--*/}
  45. <TabNavigator.Item
  46. title="商家"
  47. renderIcon={() => <Image source={{uri:'icon_tabbar_merchant_normal'}} style={styles.iconStyle} />}
  48. renderSelectedIcon={() => <Image source={{uri:'icon_tabbar_merchant_selected'}} style={styles.selectedIconStyle} />}
  49. badgeText="1"
  50. selected={this.state.selectedTab === 'shop'}
  51. onPress={() => this.setState({ selectedTab: 'shop' })}
  52. >
  53. <Shop />
  54. </TabNavigator.Item>
  55. {/*--我的--*/}
  56. <TabNavigator.Item
  57. title="我的"
  58. renderIcon={() => <Image source={{uri:'icon_tabbar_mine'}} style={styles.iconStyle} />}
  59. renderSelectedIcon={() => <Image source={{uri:'icon_tabbar_mine_selected'}} style={styles.selectedIconStyle} />}
  60. badgeText="1"
  61. selected={this.state.selectedTab === 'mine'}
  62. onPress={() => this.setState({ selectedTab: 'mine' })}
  63. >
  64. <Mine />
  65. </TabNavigator.Item>
  66. {/*--更多--*/}
  67. <TabNavigator.Item
  68. title="更多"
  69. renderIcon={() => <Image source={{uri:'icon_tabbar_misc'}} style={styles.iconStyle} />}
  70. renderSelectedIcon={() => <Image source={{uri:'icon_tabbar_misc_selected'}} style={styles.selectedIconStyle} />}
  71. badgeText="1"
  72. onPress={() => this.setState({ selectedTab: 'more' })}
  73. selected={this.state.selectedTab === 'more'}
  74. >
  75. <More />
  76. </TabNavigator.Item>
  77. </TabNavigator>
  78. );
  79. }
  80. });
  81.  
  82. const styles = StyleSheet.create({
  83. iconStyle:{
  84. width: Platform.OS === 'ios' ? 30 : 25,
  85. height:Platform.OS === 'ios' ? 30 : 25,
  86. },
  87. selectedIconStyle:{
  88. width:Platform.OS === 'ios' ? 30 : 25,
  89. height:Platform.OS === 'ios' ? 30 : 25,
  90. },
  91. });
  92.  
  93. // 输出
  94. module.exports = Main;

3.预览效果

React Native商城项目实战02 - 主要框架部分(tabBar)的更多相关文章

  1. React Native商城项目实战04 - 封装TabNavigator.Item的创建

    1.Main.js /** * 主页面 */ import React, { Component } from 'react'; import { StyleSheet, Text, View, Im ...

  2. React Native商城项目实战01 - 初始化设置

    1.创建项目 $ react-native init BuyDemo 2.导入图片资源 安卓:把文件夹放到/android/app/src/main/res/目录下,如图: iOS: Xcode打开工 ...

  3. React Native商城项目实战11 - 个人中心头部内容

    1.创建MineHeaderView.js /** * 个人中心头部内容 */ import React, { Component } from 'react'; import { AppRegist ...

  4. React Native商城项目实战10 - 个人中心中间内容设置

    1.新建一个MineMiddleView.js,专门用于构建中间的内容 /** * 个人中心中间内容设置 */ import React, { Component } from 'react'; im ...

  5. React Native商城项目实战07 - 设置“More”界面导航条

    1.More/More.js /** * 更多 */ import React, { Component } from 'react'; import { AppRegistry, StyleShee ...

  6. React Native商城项目实战05 - 设置首页的导航条

    1.Home.js /** * 首页 */ import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Te ...

  7. React Native商城项目实战06 - 设置安卓中的启动页

    1.Main 目录下新建LaunchImage.js: /** * 启动页 */ import React, { Component } from 'react'; import { AppRegis ...

  8. React Native商城项目实战03 - 包装Navigator

    1.在Home目录下新建首页详细页HomeDetail.js /** * 首页详情页 */ import React, { Component } from 'react'; import { App ...

  9. React Native商城项目实战16 - 购物中心详细页

    逻辑分析: 首页(Home)加载的购物中心组件(ShopCenter),传递url数据: ShopCenter里根据url加载购物中心详细页组件(ShopCenterDetail), ShopCent ...

随机推荐

  1. vue.js 分页加载,向上滑动,依次加载数据。

    export default { layout: 'default', data(){ return{ page:1, pageSize:10, orderListArr:[], prodListLo ...

  2. C/C++ 零碎知识点

    传递参数的一般指导原则: 对于使用传递的值而不做修改的函数: 如果数据对象很小,比如内置类型或者小型结构,按值传递. 如果数据对象是数组,只能使用指针,并将指针生命为指向const的指针. 如果数据对 ...

  3. fdisk磁盘挂载

    1.查看磁盘信息 fdisk –l 2.分区 fdisk /dev/vdb :h 帮助命令 :p 查看 :n 进行分区 e  extended  逻辑分区 p  primary partition ( ...

  4. spring之bean的自动扫描

    首先看一段applicationContext.xml中的自动扫描配置 <context:component-scan base-package="org.java.test" ...

  5. POSTGRESQL 批量权限 管理方法

    原博地址 https://yq.aliyun.com/articles/41512?spm=a2c4e.11153940.0.0.20b7640fcDiFQA 关于PostgreSQL的逻辑架构和权限 ...

  6. ListView的创建

    里面涉及到很多知识 包括3D样式的去除,重绘ListView控件,以及处理控件的边框颜色 // Test_listview_1.cpp : Defines the entry point for th ...

  7. UI控件Telerik UI for ASP.NET MVC全新发布R2 2019 SP1

    Telerik UI for ASP.NET MVC拥有使用JavaScript和HTML5构建网站和移动应用所需的70+UI部件,来满足开发者的各种需求,提供无语伦比的开发性能和用户体验.它主要是针 ...

  8. 【LuoguP5289】[十二省联考2019] 皮配

    题目链接 题目描述 略 Sol 一道背包问题 首先暴力做法设 \(dp[i][j][k]\) 表示前 \(i\) 个城市的学校被分到第一阵营 \(j\) 人 第一门派 \(k\) 人的方案数. 中间一 ...

  9. day_06 猜年龄游戏,三级菜单 ,求1 - 2 + 3 - 4 + 5...99的所有数的和(课后作业)

    1.猜年龄游戏: 要求: 允许用户最多尝试3次 每尝试3次后,如果还没猜对,就问用户是否还想继续玩,如果回答Y或y, 就继续让其猜3次,以此往复,如果回答N或n,就退出程序 如果猜对了,有三次选择奖励 ...

  10. ESP8266---TCP Client

    ESP8266WiFi库里面还有其他重要内容,比如跟http相关的 WiFiClient.WiFiServer,跟https相关的 WiFiClientSecure.WiFiServerSecure ...