react-native——tab配置及跳转
在 App 中 tab 是常见的页面类型,在 RN 里使用 react-navigation 可快速地进行 tab 配置。
假设应用有4个页面,两个是tab页面,两个是详情页面。
App.js
//应用实际场景是有redux的,这里就不删除了。不使用rudex的话,直接 return <Router />就 ok 啦!
import React, { Component } from 'react';
import { Provider } from 'react-redux';
import { PersistGate } from 'redux-persist/integration/react';
import configureStore from './store';
import Router from './router';
let store = configureStore();
export default class App extends Component {
render() {
return (
<Provider store={store.store} style={{ flex: 1 }}>
<PersistGate persistor={store.persistor}>
<Router />
</PersistGate>
</Provider>
);
}
};
router.js
import { createBottomTabNavigator, createAppContainer, createStackNavigator } from 'react-navigation';
import React from 'react';
import { Image } from 'react-native';
import Index from './view/index';
import Center from './view/center';
import Detail1 from './view/detail1';
import Detail2 from './view/detail2';
const TabNavigator = createBottomTabNavigator({
Index: {
screen: Index,
navigationOptions: {
title: '首页'
}
},
Center: {
screen: Center,
navigationOptions: {
title: '我的'
}
},
}, tabBarConfig);
const AppNavigator = createStackNavigator({
Tab: TabNavigator,
Detail1: Detail1
Detail2: Detail2
}, { headerMode: 'none' });//删除每个页面的头(一般使用自定义的)
export default createAppContainer(AppNavigator);
const tabBarConfig = { //tab的一些配置
defaultNavigationOptions: ({ navigation }) => ({
tabBarIcon: ({ focused, horizontal, tintColor }) => {//处理tab icon
const { routeName } = navigation.state;
let iconUrl;
switch (routeName) {
case 'Center':
iconUrl = focused ? require('./assets/imgs/me-full.png') : require('./assets/imgs/me.png');
break;
default:
iconUrl = focused ? require('./assets/imgs/mv-full.png') : require('./assets/imgs/mv.png');
break;
}
return <Image source={iconUrl} style={{ width: 25, height: 25 }} />;
},
}),
tabBarOptions: {
activeTintColor: '#fd0',
inactiveTintColor: '#666',
labelStyle: {
fontSize: 14
},
style: {
backgroundColor: '#fafafa',
}
}
}
应用中,跳转非tab页面,建议使用push跳转,跳转tab建议使用navigate进行跳转。
<Text onPress={() => this.props.navigation.navigate('Center')}>跳转Center</Text>
<Text onPress={() => this.props.navigation.push('Detail1')}>跳转Detail</Text>
react-native——tab配置及跳转的更多相关文章
- 史上最全Windows版本搭建安装React Native环境配置
史上最全Windows版本搭建安装React Native环境配置 配置过React Native 环境的都知道,在Windows React Native环境配置有很多坑要跳,为了帮助新手快速无误的 ...
- React Native环境配置
React Native环境配置 史上最全Windows版本搭建安装React Native环境配置 配置过React Native 环境的都知道,在Windows React Native环境配置有 ...
- React Native之配置URL Scheme(iOS Android)
React Native之配置URL Scheme(iOS Android) 一,需求分析 1.1,需要在网站中打开/唤起app,或其他app中打开app,则需要设置URL Scheme.比如微信的是 ...
- 史上最详细Windows版本搭建安装React Native环境配置 转载,比官网的靠谱亲测可用
史上最详细Windows版本搭建安装React Native环境配置 2016/01/29 | React Native技术文章 | Sky丶清| 95条评论 | 33530 views ...
- React Native之使用导航器跳转页面(react-navigation)
react-navigation是一个导航库,要使用react-navigation来实现跳转页面,首先得在项目中安装此库,由于Yarn是Facebook提供的替代npm的工具,可以加速node模块的 ...
- React Native环境配置之Windows版本搭建
接近年底了,回想这一年都做了啥,学习了啥,然后突然发现,这一年买了不少书,看是看了,就没有完整看完的.悲催. 然后,最近项目也不是很紧了,所以抽空学习了H5.自学啃书还是很无趣的,虽然Head Fir ...
- react-native学习笔记--史上最详细Windows版本搭建安装React Native环境配置
参考:http://www.lcode.org/react-native/ React native中文网:http://reactnative.cn/docs/0.23/android-setup. ...
- windows 7下React Native环境配置
React Native 是 Facebook 推出的一个用 Java 语言就能同时编写 ios,android,以及后台的一项技术,它可以做到实时热更新 .FaceBook 也号称这们技术是 “Le ...
- react native 环境配置
1. 安装Homebrew Homebrew主要用于安装后面需要安装的watchman.flow 打开MAC的终端,输入如下命令: ruby -e "$(curl -fsSL https:/ ...
随机推荐
- QML随机颜色
color=Qt.rgba(Math.random(),Math.random(),Math.random(),1)
- [错误处理]no matches found: connexion[swagger-ui] ?
问题原因: [ ] 中括号会影响shell脚本的执行 安装的时候在包名扩上双引号"" pip install "connexion[swagger-ui]" w ...
- 报错:The specified datastore driver ("com.mysql.jdbc.Driver") was not found in the CLASSPATH. Please check your CLASSPATH specification, and the name of the driver.
报错背景: CDH中集成hive插件,启动报错. 报错现象: [main]: Metastore Thrift Server threw an exception... javax.jdo.JDOFa ...
- spring 通过注解装配Bean
使用注解的方式可以减少XML的配置,注解功能更为强大,它既能实现XML的功能,也提供了自动装配的功能,采用了自动装配后,程序员所需要做的决断就少了,更加有利于对程序的开发,这就是“约定优于配置”的开发 ...
- composer autoload优化
为生产环境作准备 最后提醒一下,在部署代码到生产环境的时候,别忘了优化一下自动加载: composer dump-autoload --optimize 安装包的时候可以同样使用--optimize- ...
- 【Leetcode_easy】1047. Remove All Adjacent Duplicates In String
problem 1047. Remove All Adjacent Duplicates In String 参考 1. Leetcode_easy_1047. Remove All Adjacent ...
- 【Leetcode_easy】1160. Find Words That Can Be Formed by Characters
problem 1160. Find Words That Can Be Formed by Characters solution class Solution { public: int coun ...
- 【计算机视觉】车牌识别开源框架EasyPR介绍
之前学习了一个GitHub开源的框架,GitHub地址为: https://github.com/liuruoze/EasyPR 希望通过此篇博客详细阐述如何一步步实现车牌的识别过程. 车牌识别分 ...
- 【GStreamer开发】GStreamer基础教程09——收集媒体信息
目标 有时你需要快速的了解一个文件(或URI)包含的媒体格式或者看看是否支持这种格式.当然你可以创建一个pipeline,设置运行,观察总线上的消息,但GStreamer提供了一个工具可以帮你做这些. ...
- eNSP——实现OSPF与ACL综合实验
OSPF与ACL再前几个随笔中提到了,现在我们来做一个实例. 拓扑图: 实验案例要求: 1.企业内网运行OSPF路由协议,区域规划如图所示:2.财务和研发所在的区域不受其他区域链路不稳定性影响:3.R ...