react-native - 标题屏幕的标题没有改变“react-native 抽屉博览会”
问题描述
我正在尝试更改底部选项卡导航器的每个屏幕的标题,但是
options:{{title:'myTitle'}}
没有工作Tab.Screen
; 标题始终采用名称
<Drawer.Screen name="Drawername" component={MainTabScreen}/>
所以无论我在标题中放什么,它都需要“DrawerName”作为标题的标题,当我想用堆栈导航自定义它时,我有两个标题,比如第一个标题是不变的,我无法更改它或者像这里的截图一样删除它:
这是我的代码:
return (
<PaperProvider theme={theme}>
<AuthContext.Provider value={authContext}>
<NavigationContainer theme={theme}>
{ loginState.userToken !== null ? (
<Drawer.Navigator drawerContent={props => <DrawerContent {...props} />}>
<Drawer.Screen name="DrawerName" component={MainTabScreen}/>
<Drawer.Screen name="SupportScreen" component={SupportScreen} />
<Drawer.Screen name="SettingsScreen" component={SettingsScreen} />
<Drawer.Screen name="BookmarkScreen" component={BookmarkScreen} />
</Drawer.Navigator>
)
:
<RootStackScreen/>
}
</NavigationContainer>
</AuthContext.Provider>
</PaperProvider>
);
}
export default App;
主选项卡屏幕:
import { createMaterialBottomTabNavigator } from '@react-navigation/material-bottom-tabs';
import { createStackNavigator } from '@react-navigation/stack';
import Icon from 'react-native-vector-icons/Ionicons';
import HomeScreen from './HomeScreen';
import DetailsScreen from './DetailsScreen';
import ExploreScreen from './ExploreScreen';
import ProfileScreen from './ProfileScreen';
const HomeStack = createStackNavigator();
const DetailsStack = createStackNavigator();
const ExploreStack = createStackNavigator();
const Tab = createMaterialBottomTabNavigator();
const MainTabScreen = () => (
<Tab.Navigator
initialRouteName="Home"
activeColor="#fff"
>
<Tab.Screen
name="Home"
component={HomeScreen}
options ={{
title: "Home",
tabBarLabel: 'Home',
tabBarColor: '#009387',
tabBarIcon: ({ color }) => (
<Icon name="ios-home" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="Notifications"
component={DetailsStackScreen}
options={{
tabBarLabel: 'Updates',
tabBarColor: '#1f65ff',
tabBarIcon: ({ color }) => (
<Icon name="ios-notifications" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="Profile"
component={ProfileScreen}
options={{
tabBarLabel: 'Profilee',
tabBarColor: '#694fad',
tabBarIcon: ({ color }) => (
<Icon name="ios-person" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="Explore"
component={ExploreStackScreen}
options={{
tabBarLabel: 'Explore',
tabBarColor: '#d02860',
tabBarIcon: ({ color }) => (
<Icon name="ios-aperture" color={color} size={26} />
),
}}
/>
</Tab.Navigator>
);
export default MainTabScreen;
const DetailsStackScreen = ({navigation}) => (
<DetailsStack.Navigator screenOptions={{
headerStyle: {
backgroundColor: '#1f65ff',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold'
}
}}>
<DetailsStack.Screen name="Details" component={DetailsScreen} options={{
headerLeft: () => (
<Icon.Button name="ios-menu" size={25} backgroundColor="#1f65ff" onPress={() => navigation.openDrawer()}></Icon.Button>
)
}} />
</DetailsStack.Navigator>
);
const ExploreStackScreen = ({navigation}) => (
<ExploreStack.Navigator screenOptions={{
headerStyle: {
backgroundColor: '#1f65ff',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold'
}
}}>
<ExploreStack.Screen name="Details" component={ExploreScreen} options={{
headerLeft: () => (
<Icon.Button name="ios-menu" size={25} backgroundColor="#1f65ff" onPress={() => navigation.openDrawer()}></Icon.Button>
)
}} />
</ExploreStack.Navigator>
);
解决方案
推荐阅读
- python - 将张量流模型转换为 onnx 中的 TypeError
- javascript - 具有多个参数的反应搜索
- google-api - YouTube 入门配额
- javascript - 为什么我的时间戳到日期格式会给出很大的年份?
- c++ - SIGABRT 在 Mac OS X 上使用 GCC 抛出和捕获异常
- algorithm - 使用递归查找所有总和为 N 并包含 K 个元素的数字的所有组合
- nuxt.js - 如何在 Nuxt 应用程序中停止多个 Favicon 请求?
- python - 尝试在 cmd 中运行 python 脚本
- c# - 通过 SSL 访问时服务器无法运行
- python - 从 xml 检索数据时出现 IndexError