reactjs - 如何在我的 MainTabHome 上添加标题名称和图标
问题描述
下面是我的 MainTopTab 的代码,并且 MainTabScreen 在我的应用程序上的另一个 Navigation =>“createStackNavigator”上被调用。因为它是我的第二个主要选项卡。我也无法设置图标和更改名称。因为它不是类组件,所以我无法使用下面的代码
static navigationOptions = {
title: 'Home' }
无论如何在不使用类组件的情况下设置标题和图标。?
import { createMaterialTopTabNavigator } from 'react-navigation-tabs';
import { createStackNavigator } from 'react-navigation-stack';
import { createAppContainer } from 'react-navigation';
//components
import All from './All';
import MostView from './MostView';
import Reco from './Reco';
import Recent from './Recent';
const MainTabScreen = createMaterialTopTabNavigator(
{
All: { screen: All },
MostView: { screen: MostView },
Reco: { screen: Reco },
Recent: { screen: Recent },
},
{
initialRouteName: 'All',
tabBarPosition: 'top',
swipeEnabled: true,
animationEnabled: true,
tabBarOptions: {
activeTintColor: '#744DD2',
inactiveTintColor: '#4f4955',
style: {
backgroundColor: '#fff',
//height: 150
},
labelStyle: {
textAlign: 'center',
},
indicatorStyle: {
borderBottomColor: '#744DD2',
borderBottomWidth: 2.6,
},
},
},
);
const TopTab = createStackNavigator({
MainTabScreen: {
screen: MainTabScreen,
navigationOptions: {
headerStyle: {
backgroundColor: '#744DD2',
},
headerTintColor: '#FFFFFF',
title: 'Clubs',
},
},
});
const MainTopTab = createAppContainer(MainTabScreen);
export default MainTopTab;
解决方案
取决于您使用的是哪个版本react-navigation
,如果您使用的是最新版本 5.x ,您可以执行以下操作:
const TopTab = createStackNavigator({
MainTabScreen: {
component: MainTabScreen,
options={{
headerTitle: <Text>Home</Text>,
headerRight: () => (
<Image source={{ uri: ''}} />
),
}},
},
});
推荐阅读
- javascript - 将纬度/经度投影到像素
- java - 降低 switch 语句的圈复杂度
- blazor - Blazor Blazored.SessionStorage http 错误 500 一旦注入 index.razor
- php - Laravel 请求验证:根据“名称”验证另一个字段
- javascript - 无法通过 React 前端和 Flask 后端集成
- haskell - 替代在 Haskell 中编写 [i..]
- javascript - 试图获取单个产品并将其显示在组件中但它不起作用,我有一个服务组件来显示此数据
- nlp - 词性标注:已知词和未知词有什么区别?
- reactjs - React context API-我如何从 useEffect 钩子中分派一个动作?
- java - Java 线程 CPU 使用率