我的React Native应用程序有问题。
我希望第一个屏幕截图只有一个标题,而不是这里的两个标题,并保留选项卡导航器,但当单击“提及légales”按钮时,将被重定向到CGUScreen,带有类似this one的标题,底部没有选项卡导航器。
BottomTabNavigator.js:
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中,我有:
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中创建另一个堆栈导航器。
发布于 2020-06-08 18:23:13
<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
}
}}https://stackoverflow.com/questions/62259637
复制相似问题