我似乎无法在新版本的React Navigation中将标题配置为null。我可以使用headerTransparent选项将其设置为透明,但是它看起来像标题仍然存在,因为屏幕仍需要一个名称。
这是我最初的样子,使用一个新的Expo应用程序模板
而这就是标题透明时的效果,基本上就是我想看到的,但还是会强制显示标题。
我不想要导航栏,但这似乎是默认行为。我尝试查看文档,看是否有类似的属性可删除标题,但在选项页面遇到了404页面: https://reactnavigation.org/docs/zh-Hans/navigation-options.html 我对React Native很陌生,所以可能有些误解。但是文档对此不够清晰,我也找不到一个直接回答此问题的stackoverflow问题。
这是我的App.js:
这是我的BottomTabNavigator.js代码,非常类似于Expo提供的模板代码。
我不想要导航栏,但这似乎是默认行为。我尝试查看文档,看是否有类似的属性可删除标题,但在选项页面遇到了404页面: https://reactnavigation.org/docs/zh-Hans/navigation-options.html 我对React Native很陌生,所以可能有些误解。但是文档对此不够清晰,我也找不到一个直接回答此问题的stackoverflow问题。
这是我的App.js:
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import BottomTabNavigator from './navigation/BottomTabNavigator';
import useLinking from './navigation/useLinking';
const Stack = createStackNavigator();
........
<NavigationContainer ref={containerRef} initialState={initialNavigationState}>
<Stack.Navigator>
<Stack.Screen name="root" component={BottomTabNavigator} options={{headerTransparent: true}}/>
</Stack.Navigator>
</NavigationContainer>
这是我的BottomTabNavigator.js代码,非常类似于Expo提供的模板代码。
import * as React from 'react';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import TabBarIcon from '../components/TabBarIcon';
import HomeScreen from '../screens/Home';
import SearchScreen from '../screens/Search';
const BottomTab = createBottomTabNavigator();
const INITIAL_ROUTE_NAME = 'Home';
export default function BottomTabNavigator({ navigation, route }) {
navigation.setOptions({ headerTitle: getHeaderTitle(route) });
return (
<BottomTab.Navigator initialRouteName={INITIAL_ROUTE_NAME}>
<BottomTab.Screen
name="Home"
component={HomeScreen}
options={{
title: 'Home',
tabBarIcon: ({ focused }) => <TabBarIcon focused={focused} name="md-home" />
}}
/>
<BottomTab.Screen
name="Search"
component={SearchScreen}
options={{
title: 'Search',
tabBarIcon: ({ focused }) => <TabBarIcon focused={focused} name="md-search" />,
}}
/>
</BottomTab.Navigator>
);
}
function getHeaderTitle(route) {
const routeName = route.state?.routes[route.state.index]?.name ?? INITIAL_ROUTE_NAME;
switch (routeName) {
case 'Home':
return 'How to get started';
case 'Appointments':
return 'Your appointments';
case 'Search':
return 'Search for services';
case 'Account':
return 'Account'
}
}