react-navigation使用
来源:互联网 发布:mac粉底液色号选择 编辑:程序博客网 时间:2024/06/10 07:44
1.react-navigation,建立导航
页面跳转和搭建TabBar,使用的是React Navigation组件,需要npm install --save react-navigation,页面跳转用
http://www.jianshu.com/p/0014506a9b77
const router = StackNavigator({ 导航页: { screen: tabBar }, 广告页: { screen: Ad }, 设置页: { screen: Set }});
TabBar用:
const tabBar = TabNavigator({ 首页: { screen: Home, navigationOptions: { tabBarLabel: '首页', tabBarIcon: ({ tintColor, focused }) => ( <Ionicons name={focused ? 'ios-home' : 'ios-home-outline'} selectedIconName="ios-home" size={20} style={{ color: tintColor }} /> ), } }, 发现: { screen: Find, navigationOptions: { tabBarLabel: '发现', tabBarIcon: ({ tintColor, focused }) => ( <Ionicons name={focused ? 'ios-cube' : 'ios-cube-outline'} size={20} style={{ color: tintColor }} /> ), } }, 我的: { screen: My, navigationOptions: { tabBarLabel: '我的', tabBarIcon: ({ tintColor, focused }) => ( <Ionicons name={focused ? 'ios-person' : 'ios-person-outline'} size={20} style={{ color: tintColor }} /> ), } },}, { tabBarPosition: 'bottom', swipeEnabled: false, // 禁止左右滑动 tabBarOptions: { activeTintColor: '#666699', // 文字和图片选中颜色 inactiveTintColor: '#CC9999', // 文字和图片默认颜色 showIcon: true, // android 默认不显示 icon, 需要设置为 true 才会显示 indicatorStyle: { height: 0 }, // android 中TabBar下面会显示一条线,高度设为 0 后就不显示线了, 不知道还有没有其它方法隐藏??? style: { backgroundColor: '#FFFF99', // TabBar 背景色 }, labelStyle: { fontSize: 12, // 文字大小 }, },});
需要注意的是,需要把TabBar嵌套在StackNavigator里使用,不然进入第二页下面导航栏任然不会消失,这点让我觉得使用非常不爽,因为我理解TabBar逻辑上是最外一层,按钮上每个首页面再通过StackNavigator嵌套跳转页面,然而它是因为堆栈的缘故,如果TabBar放在表层,嵌套页面永远在TabBar下一级,不会盖过TabBar,但是如果把TabBar嵌套在StackNavigator里的话,新打开的一页就会占整屏幕,但是感觉这样写会对整个程序的路线非常模糊。(不过也许router方法会对程序线路管理有帮助?没细看)
2.react-native-vector-icons:图标地址
配置的东西有点多,不过写的很详细,一步步走就好
import Ionicons from 'react-native-vector-icons/Ionicons';//首页图标配置 首页: { screen: Home, navigationOptions: { tabBarLabel: '首页', tabBarIcon: ({tintColor,focused}) => ( <Ionicons name={focused ? 'ios-home' : 'ios-home-outline'} selectedIconName="ios-home" size={20} style={{ color: tintColor }} /> ), } },
,
丑陋的首页以及跳转,把最基础的模型搭建好,之后就可以开始尝试各种组件了~
1 0
- react-navigation Navigation使用
- react-navigation 简单使用
- react-navigation使用
- react-navigation使用技巧
- react-navigation使用
- react-navigation使用心得
- React Navigation基础使用
- react-navigation使用技巧
- react-navigation 使用详解
- react-navigation使用技巧
- react-navigation使用技巧
- react-navigation的使用
- react-navigation 使用详解
- react-navigation使用技巧
- react-navigation之TabNavigator使用
- React-navigation StackNavigator 使用攻略
- react-native Navigation使用一
- 【React Native开发】- React Navigation的使用
- react-navigation 简单使用
- XShell提示Connection closed by foreign host的问题 和 路由器分配IP的规则
- linux下的mysql下载
- JS创建对象之稳妥构造函数模式
- Swift 包管理器教程
- react-navigation使用
- Android开发进阶—线程和线程池
- 单点登陆(一):思考
- 面Android的时候要想些什么
- poj 1458 最长公共子序列
- [Leetcode] 137. Single Number II 解题报告
- 代理模式之静态代理的简单实现---理解AOP(面向切面编程)的前奏---想要理解AOP,必须先理解一下
- const用法总结
- AngularJS搭建单页APP(拉钩)