React Native 之createDrawerNavigator和createSwitchNavigator
其他代码接上篇文章
createDrawerNavigator 抽屉
createSwitchNavigator 模拟登录=>主界面
index.js
/*** @format*/import {AppRegistry} from 'react-native'; import {createAppContainer} from 'react-navigation'; import App from './navigators/AppNavigators'; import {name as appName} from './app.json';AppRegistry.registerComponent(appName, () => App);
AppNavigators.js
import React from 'react'; //只要在页面中使用了基础组件 都需要导入这句话 不然会报错 import {Button,Platform,ScrollView,SafeAreaView} from 'react-native'; import { createStackNavigator,createAppContainer,createBottomTabNavigator,createMaterialTopTabNavigator,createDrawerNavigator,DrawerItems,createSwitchNavigator,} from 'react-navigation'; import HomePage from '../pages/HomePage'; import Page1 from '../pages/Page1'; import Page2 from '../pages/Page2'; import Page3 from '../pages/Page3'; import Page4 from '../pages/Page4'; import Page5 from '../pages/Page5'; import Login from '../pages/Login'; import Ionicons from 'react-native-vector-icons/Ionicons' import MaterialIcons from 'react-native-vector-icons/MaterialIcons'const DrawerNav=createDrawerNavigator({Page4:{screen:Page4,navigationOptions:{drawerLabel:'Page4',drawerIcon:({tintColor})=>(<MaterialIconsname={'drafts'}size={24}style={{color:tintColor}}/> )}},Page5:{screen:Page5,navigationOptions:{drawerLabel:'Page5',drawerIcon:({tintColor})=>(<MaterialIconsname={'move-to-inbox'}size={24}style={{color:tintColor}}/> )}} }, {initialRouteName:'Page4',contentOptions:{activeTintColor:'#e91e63',},contentComponent:(props)=>(<ScrollView style={{backgroundColor:'#789',flex:1}}><SafeAreaView forceInset={{top:'always',horizontal:'never'}}><DrawerItems {...props}/></SafeAreaView></ScrollView> ) } );const AppTopNavigator=createMaterialTopTabNavigator({Page1:{screen:Page1,navigationOptions:{tabBarLabel: 'All'}},Page2:{screen:Page2,navigationOptions:{tabBarLabel: 'iOS'}},Page3:{screen:Page3,navigationOptions:{tabBarLabel: 'Android'}},Page4:{screen:Page4,navigationOptions:{tabBarLabel: 'React-Native'}}, },{tabBarOptions:{tabStyle:{mindWidth: 50},upperCaseLabel:false,//是否使标签大写 默认truescrollEndabled:true,//是否支持选项卡滚动 默认false style:{backgroundColor:'#678'//TabBar背景色 },indicatorStyle:{height:2,backgroundColor:'white'},//标签指示器样式 labelStyle:{fontSize:13,marginTop:6,marginBottom:6},// 文字的样式 } } );const AppBottomNavigator=createBottomTabNavigator({Page1:{screen:Page1,navigationOptions:{tabBarLabel: '最热',tabBarIcon:({tintColor,focused})=>(<Ioniconsname={'ios-home'}size={26}style={{color:tintColor}}/>) }},Page2:{screen:Page2,navigationOptions:{tabBarLabel: '趋势',tabBarIcon:({tintColor,focused})=>(<Ioniconsname={'ios-appstore'} // 全部小写size={26}style={{color:tintColor}}/>) }},Page3:{screen:Page3,navigationOptions:{tabBarLabel: '收藏',tabBarIcon:({tintColor,focused})=>(<Ioniconsname={'ios-people'}size={26}style={{color:tintColor}}/>) }},Page4:{screen:Page4,navigationOptions:{tabBarLabel: '我的',tabBarIcon:({tintColor,focused})=>(<Ioniconsname={'ios-aperture'}size={26}style={{color:tintColor}}/>) }},},{tabBarOptions:{activeTintColor: Platform.OS === 'ios' ? '#e91e63' : '#fff',}} );const AppStack = createStackNavigator({Home: {screen: HomePage},Page1: {screen: Page1},Page2: {screen: Page2,navigationOptions: {//在这里定义每个页面的导航属性,静态配置title: "This is Page2.",}},Page3: {screen: Page3,navigationOptions: (props) => {//在这里定义每个页面的导航属性,动态配置const {navigation} = props;const {state, setParams} = navigation;const {params} = state;return {title: params.title ? params.title : 'This is Page3',headerRight: (<Buttontitle={params.mode === 'edit' ? '保存' : '编辑'}onPress={()=>{setParams({mode: params.mode === 'edit' ? '' : 'edit'})}}/> ),}}},Bottom:{screen:AppBottomNavigator,navigationOptions:{title:'BottomNavigator'}},Top:{screen:AppTopNavigator,navigationOptions:{title:'TopNavigator'}},DrawerNav:{screen:DrawerNav,navigationOptions:{title:'This is DrawNavigator',}} },{defaultNavigationOptions: {// header: null,// 可以通过将header设为null 来禁用StackNavigator的Navigation Bar }} );const AuthStack = createStackNavigator({Login: {screen: Login}, },{navigationOptions: {// header: null,// 可以通过将header设为null 来禁用StackNavigator的Navigation Bar } });const AppStackNavigator = createSwitchNavigator({Auth: AuthStack,App: AppStack,},{initialRouteName: 'Auth',} );const App = createAppContainer(AppStackNavigator) export default App
View Code
Login.js
/*** Sample React Native App* https://github.com/facebook/react-native** @format* @flow*/import React, {Fragment,Component} from 'react';import {StyleSheet,View,Text,Button,} from 'react-native';export default class Login extends Component {render(){const {navigation}=this.props;return (<View style={styles.container}><Text style={styles.welcome}>欢迎来到Login</Text><Buttontitle={'Go App'}onPress={()=>{navigation.navigate('App');}}/></View> );}}const styles=StyleSheet.create({container:{flex:1,},welcome:{fontSize:20,textAlign: 'center',}});
View Code
效果图
转载于:https://www.cnblogs.com/liuw-flexi/p/11443003.html
React Native 之createDrawerNavigator和createSwitchNavigator相关推荐
- 如何在React Native中使用react-navigation 5处理导航
React-navigation is the navigation library that comes to my mind when we talk about navigation in Re ...
- 电影天堂React Native 客户端V2.0发布
电影天堂React Native 客户端 重新开始! 具体更新以https://github.com/XboxYan/DYTT为准. 重新开始 两年前发布了第一个版本. 现在, 使用最新的react- ...
- [React Native Development] Camping Spots Finder应用程序用户界面克隆第一部分-地图视图用户界面...
本教程的灵感来自房地产模板,该模板使我们能够构建功能齐全的,随时可以部署的移动应用程序,任何人都可以用来构建自己的React Native应用程序. 本教程从React UI Kit的Camping ...
- 电影天堂React Native客户端V2.0
电影天堂React Native客户端V2.0 DYTT 重新开始 免责声明 为什么要重新开始呢 特色 项目依赖 安装 下载 相关截图 欢迎页 首页 功能菜单 历史记录 收藏 主题颜色 搜索 搜索结果 ...
- React Native项目配置路由和选项卡导航__React Navigation的使用
React Native 配置路由 在网上看了很多例子跟着写,发现都不行,发现之前的写法都已经弃用了,跟着官方一步步来吧. 参考官方文档:React Navigation 先创建好项目: npx re ...
- mobx在react中应用_借助React Native Elements,Jest和MobX MST可以轻松实现现实世界中的ReactNative应用...
mobx在react中应用 by Qaiser Abbas 由Qaiser Abbas 借助React Native Elements,Jest和MobX MST可以轻松实现现实世界中的ReactNa ...
- fragment中文网_更新 · React Native 中文网
时刻将 React Native 更新到最新的版本,可以获得更多 API.视图.开发者工具以及其他一些好东西(译注:官方开发任务繁重,人手紧缺,几乎不会对旧版本提供维护支持,所以即便更新可能带来一些兼 ...
- React Native —— App
使用 React Native 作为 app 框架,Redux 作为数据层,因此我们需要选用一些支持性的技术和工具: 开源的 Parse Server 做数据存储 - 运行在 Node.js 上. F ...
- 【React Native】iOS原生导航跳转RN页面
上一篇介绍了React Native使用react-navigation进行导航跳转页面,现在我们介绍下原生iOS中怎么导航进一个新的React Native页面. 一.原生跳转React Nativ ...
最新文章
- javascript禁止修改对象
- FPGA的设计艺术(15)逻辑设计及仿真利器之各式各样的循环
- 在.net 2.0中使用了masterpager 重写WebForm_OnSubmit()
- 【Android 组件化】使用 Gradle 实现组件化 ( Gradle 变量定义与使用 )
- TIMESTAMP 与 explicit_defaults_for_timestamp
- python2.7.15安装步骤_升级到python2.7.15后安装pip
- 五问唐骏:泡妞真的如你说的那么容易?
- Linux信号signal的介绍和示例
- Java面试题全集(上)
- 2017 东北四省赛热身赛 C
- 算法—— LeetCode 第一遍
- python_day7
- 日本企业遭遇严重用工短缺
- gnuplot绘制xxx.plt文件生成图形
- 如何在手机APP中通过H5方式集成监控摄像头实时直播画面
- android手机变windows8,安卓手机如何把手机界面投屏到windows8/10电脑上
- BZOJ 1064 假面舞会
- repo file=sys.stderr 错误完美解决
- 贪心算法 田忌赛马问题
- 有写字好看的人给点实用性技巧吗?
热门文章
- matlab数组元素的比较大小排序,MATLAB数组元素的排序
- NPDP产品经理小知识:平衡计分卡(二)
- 简述UIImagePickerController的属性和用法
- FX3U以太网模块MC协议,三菱FX3U以太网MC通讯协议
- ps性能打不开的解决方法
- 【贴图、OCR】snipaste、天若OCR-win软件
- 消息队列MQ 之 Kafka
- yum 安装mysql 5.7
- 【011】17GRE-自动根据艾宾浩斯曲线铺排学习计划
- 2019湖南大学计算机考研分数线,湖南大学2019年考研分数线完整查看 2019湖大复试过线多少分...