首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法组合导航器

无法组合导航器
EN

Stack Overflow用户
提问于 2020-06-08 18:05:44
回答 1查看 30关注 0票数 0

我的React Native应用程序有问题。

I have this

Other tab example

我希望第一个屏幕截图只有一个标题,而不是这里的两个标题,并保留选项卡导航器,但当单击“提及légales”按钮时,将被重定向到CGUScreen,带有类似this one的标题,底部没有选项卡导航器。

BottomTabNavigator.js:

代码语言:javascript
复制
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { createStackNavigator } from '@react-navigation/stack'
import * as React from 'react';

import TabBarIcon from '../components/TabBarIcon';
import HomeScreen from '../screens/HomeScreen';
import OffresScreen from '../screens/OffresScreen';
import PlusScreen from '../screens/PlusScreen';
import CGUScreen from '../screens/CGUScreen';
import { NavigationContainer } from '@react-navigation/native';

const BottomTab = createBottomTabNavigator();
const CGUStack = createStackNavigator();

export default function BottomTabNavigator({ navigation, route }) {

  navigation.setOptions({ headerTitle: getHeaderTitle(route) });

  function CGUStackScreen() {
   return (
     <NavigationContainer independent={true}>
      <CGUStack.Navigator initialRouteName="Plus">
        <CGUStack.Screen name="Plus" component={PlusScreen} />
        <CGUStack.Screen name="CGU" component={CGUScreen} />
      </CGUStack.Navigator>
    </NavigationContainer>
    );
  }

  return (
    <BottomTab.Navigator initialRouteName={'Home'}>
      <BottomTab.Screen
        name="Home"
        component={HomeScreen}
        options={{
          title: 'Catalogues',
          tabBarIcon: ({ focused }) => <TabBarIcon focused={focused} name="md-book" />,
        }}
      />
      <BottomTab.Screen
        name="Offres"
        component={OffresScreen}
        options={{
          title: 'Offres',
          tabBarIcon: ({ focused }) => <TabBarIcon focused={focused} name="md-flash" />
        }}
      />
      <BottomTab.Screen
        name="Plus"
        component={CGUStackScreen}
        options={{
          title: 'Plus',
          tabBarIcon: ({ focused }) => <TabBarIcon focused={focused} name="md-menu" />,
          navigationOptions: {
            headerMode: 'none',
          }
        }}
      />
    </BottomTab.Navigator>
  );
}

function getHeaderTitle(route) {
  const routeName = route.state?.routes[route.state.index]?.name ?? 'Home';

  switch (routeName) {
    case 'Home':
      return 'Catalogues';
    case 'Plus':
      return 'Plus';
    case 'Offres':
      return 'Offres';
    case 'CGU':
      return 'CGU';
  }
}

在我的App.js中,我有:

代码语言:javascript
复制
const Stack = createStackNavigator();
<NavigationContainer linking={LinkingConfiguration}>
 <Stack.Navigator>
  <Stack.Screen name="Root" component={BottomTabNavigator} />
 </Stack.Navigator>
</NavigationContainer>

我真的不明白我的代码出了什么问题。另外,如何从PlusScreen.js中将按钮重定向到CGUScreen?感谢您的帮助!:)

更新:我现在有了导航功能,但它保留了第二个标题和底部的标签。

更新2:它可以工作,使用App.js中的堆栈导航器,而不是在Tab Navigator中创建另一个堆栈导航器。

EN

回答 1

Stack Overflow用户

发布于 2020-06-08 18:23:13

代码语言:javascript
复制
<BottomTab.Screen
    name="Plus"
    component={CGUStackScreen}
    options={{
      title: 'Plus',
      tabBarIcon: ({ focused }) => <TabBarIcon focused={focused} name="md-menu" />,
      navigationOptions: {
        headerMode: 'none',
        tabBarVisible: false,  //<---- Here hide tabbar in CGUStackScreen
      }
    }}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62259637

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档