一起使用Tab和Stack Navigator

时间:2018-09-24 17:41:40

标签: react-native react-navigation

我正在使用React-Navigation

在React-Native上构建一个应用程序

现在,在我内部使用的是Stack-NavigationTabNavigator(已更新DrawerNavigator

import { 
  createStackNavigator,
   TabNavigator,
   DrawerNavigator
 } from 'react-navigation';

import CoinCapCharts from "./src/container/CoinCapCharts.js"

import CoinCap from './src/container/CoinCap.js';


//THis is being Exported to App.js

 export const Tab = TabNavigator({
  TabA: {
    screen: CoinCap 
  },
  TabB: {
    screen: CoinCap
  }
}, {
  order: ['TabA', 'TabB'],
  animationEnabled: true,
})

export const MyScreen = createStackNavigator({
  Home: { 
    screen: CoinCap
  },
  CoinCapCharts: {
     screen: CoinCapCharts
    }
},{
    initialRouteName: 'Home',
    headerMode: 'none'
});


export const Drawer = DrawerNavigator({
  Tabs: { screen: Tab },
  Stack: { screen: MyScreen },
})

我将其导入App.js中,我正在做类似的事情

import React from 'react';
import {
  Drawer
 }from './Screen.js';
import {
  View
} from 'react-native';

export default class App extends React.Component {
  render() {
    return (
    <View>
      <Drawer/>
      <Tab/>
      </View>
    );
  }
}

现在,这确实是我第一次运行应用程序时显示的Tab,但是导航到其他屏幕并返回后,它似乎不再显示该Tab

[问题:] ,我可能做错了什么以及如何解决?

enter image description here

1 个答案:

答案 0 :(得分:1)

尝试在另一个中定义一个。 像这样:

const Tab =  TabNavigator({
  TabA: {
    screen: Home 
  },
  TabB: {
    screen: Home
  }
}, {
  order: ['TabA', 'TabB'],
  animationEnabled: true,
})

export const MyStack = createStackNavigator({
  Home: { 
    screen: Home 
  },
  CoinCapCharts: {
     screen: CoinCapCharts
  },
  Tab: { 
    screen: Tab
  },
},{
    initialRouteName: 'Home',
    headerMode: 'none'
});

现在,渲染MyStack(不确定Screen是最好的名字:)

export default class App extends React.Component {
  render() {
    return (
    <View>
      <MyStack />
      </View>
    );
  }
}