简体   繁体   English

如何在 React Native 中使用 CreateBottomTabNavigator?

[英]How To Use CreateBottomTabNavigator in React Native?

Current code当前代码

App.js应用程序.js

import React from 'react';

import {NavigationContainer} from '@react-navigation/native';
import {createStackNavigator} from '@react-navigation/stack';
import { Icon } from 'react-native-elements';

import HomeScreen from 'app/src/screens/home/Index';
import DetailScreen from 'app/src/screens/home/Detail';
import MypageScreen from 'app/src/screens/mypage/Index';
import InitialScreen from 'app/src/screens/authentication/Initial';

const Home = {
  screen: HomeScreen,
  navigationOptions: ({ navigation }) => {
    return {
      title: 'Home',
    };
  },
};

const Detail = {
  screen: DetailScreen,
  navigationOptions: ({ navigation }) => {
    return {
      title: 'Detail',
    };
  },
};

const Mypage = {
  screen: MypageScreen,
  navigationOptions: ({ navigation }) => {
    return {
      title: 'MyPage',
    };
  },
};

const Initial = {
  screen: InitialScreen,
  navigationOptions: ({ navigation }) => {
    return {
      title: 'Initial',
    };
  },
}

const HomeStack = createStackNavigator(
  {
    Home,
    Detail,
  },
  {
    initialRouteName: 'Home',
    navigationOptions: {
      tabBarIcon: <Icon name="home" />,
    },
  }
);

const MypageStack = createStackNavigator(
  {
    Mypage,
  },
  {
    initialRouteName: 'Mypage',
    navigationOptions: {
      tabBarIcon: <Icon name="person" />,
    },
  }
);


const postLoginNavigator = createBottomTabNavigator({
  Home: HomeStack,
  Mypage: MypageStack,
});

const AppNavigator = createStackNavigator({
  Initial,
  PostLogin: postLoginNavigator
},{
  mode: 'modal',
  headerMode: 'none',
  initialRouteName: 'Initial'
})

const AppContainer = createAppContainer(AppNavigator);

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

What I want to do我想做的事

I wanna make tabs in bottom using createBottomTabNavigator.我想使用 createBottomTabNavigator 在底部制作标签。 Home and My Page tabs.主页和我的页面选项卡。

Error that I'm facing我面临的错误

Error: Creating a navigator doesn't take an argument.错误:创建导航器不带参数。 Maybe you are trying to use React Navigation 4 API with React Navigation 5?也许您正在尝试将 React Navigation 4 API 与 React Navigation 5 一起使用?

ps ps

I'm using我在用着

"@react-navigation/native": "^5.2.3",
"@react-navigation/stack": "^5.2.8",
"@react-navigation/bottom-tabs": "^5.0.6",

I would appreciate it if you could give me any advices.如果您能给我任何建议,我将不胜感激。

Add the bottomTabNavigator inside a StackNavigator.在 StackNavigator 中添加 bottomTabNavigator。 In future, if you are adding more screens you can add it to the stack将来,如果您要添加更多屏幕,您可以将其添加到堆栈中

import React from 'react';

import {NavigationContainer} from '@react-navigation/native';
import {createStackNavigator} from '@react-navigation/stack';
import { createBottomTabNavigator } from 'react-navigation-tabs';
import { Icon } from 'react-native-elements';

import HomeScreen from 'app/src/screens/home/Index';
import MypageScreen from 'app/src/screens/mypage/Index';

const Stack = createStackNavigator();
const Tab = createBottomTabNavigator();

const MyTabs = () => {
    <Tab.Navigator>
      <Tab.Screen name="Home" component={HomeScreen} />
      <Tab.Screen name="Mypage" component={MypageScreen} />
    </Tab.Navigator>
}

const AuthStack = () => (
<Stack.Navigator>
      <Stack.Screen name="Tabs" component={MyTabs} />
    </Stack.Navigator>
);

const AuthenticationNavigator = () => (
  <NavigationContainer>
    <AuthStack />
  </NavigationContainer>
);

export default AuthenticationNavigator;
    const MyTabs = () => { 
     return(
        <Tab.Navigator>
          <Tab.Screen name="Home" component={HomeScreen} />
          <Tab.Screen name="Mypage" component={MypageScreen} />
        </Tab.Navigator>);
    }

Can you try this?你能试试这个吗? I think I missed the return statement我想我错过了退货声明

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

相关问题 React Native createStackNavigator 和 createBottomTabNavigator - React Native createStackNavigator and createBottomTabNavigator 反应原生 createBottomTabNavigator - React native createBottomTabNavigator 在 React Native 中使用 createBottomTabNavigator 和 createStackNavigator - Using createBottomTabNavigator with createStackNavigator in React Native 在React Native的createBottomTabNavigator上添加事件处理程序 - Adding an event handler on a createBottomTabNavigator of React Native React Native Navigation-createBottomTabNavigator和隐藏选项卡栏 - React Native Navigation - createBottomTabNavigator and hiding Tab Bar React-Native 的 createBottomTabNavigator 在 ReactJS 中的等价物是什么? - What is the equivalent of React-Native's createBottomTabNavigator in ReactJS? 使用react-native中的Animation隐藏和显示createBottomTabNavigator标签栏 - Hide and Show createBottomTabNavigator tabbar with Animation in react-native 如何使用 createBottomTabNavigator 为每个选项卡使用不同的图标? - How to use different icons for each tab with createBottomTabNavigator? 使用最新 react-native 版本的 createBottomTabNavigator 和 Unrecognized 字体系列出现问题 - Having problem with createBottomTabNavigator and Unrecognized font family using the latest react-native version 使用redux存储访问来创建createBottomTabNavigator - React createBottomTabNavigator with redux store access
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM