简体   繁体   English

同时使用StackNavigation和TabNavigation

[英]StackNavigation and TabNavigation in the Same time

I wanted to know how I can add tab navigation and stack navigation with react navigation in react native. 我想知道如何在react native中添加标签导航和堆栈导航以及react导航。

 import React, { Component } from 'react';
    import { Platform, StyleSheet, Text, View, Image, TouchableHighlight, ScrollView, Dimensions } from 'react-native';
    import {StackNavigator,TabNavigator} from 'react-navigation';
    import Scores from './src/scores.js';
    import Profile from './src/profile.js';
    import Favourite from './src/favourite.js'

   const MyApp = TabNavigator({
      Scores: {
        screen: Scores,
      },
      Favs: {
        screen:Favourite ,
      },
      Profile: {
        screen:Profile,
      },
    }, {
      tabBarPosition: 'bottom',
      animationEnabled: false,
      tabBarOptions: {
        activeTintColor: '#F7C01C',
      },
    });

    export default MyApp;

Here I have TabNavigation only working but I still need to add the stacknavigatio and maybe later I need to add Drawer Navigation. 在这里,我只能使用TabNavigation,但仍需要添加stacknavigatio,也许以后需要添加Drawer Navigation。

You can nest Navigators. 您可以嵌套导航器。 Just create a StackNavigator exactly as you created your TabNavigator and add it instead of a screen. 只需创建与创建TabNavigator完全相同的StackNavigator ,然后添加它而不是屏幕即可。

const MyFavs =  StackNavigator({
  FavouriteList: {
    screen: FavouriteList,
  },
  ViewFavourite: {
    screen: ViewFavourite,
  },
}, {
  initialRouteName: 'FavouriteList'
});


const MyApp = TabNavigator({
  Scores: {
    screen: Scores,
  },
  Favs: {
    screen: MyFavs,
  },
  Profile: {
    screen: Profile,
  },
}, {
  tabBarPosition: 'bottom',
  animationEnabled: false,
  tabBarOptions: {
    activeTintColor: '#F7C01C',
  },
});

export default MyApp;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM