React native 反应导航如何动态更改每个选项卡的标题导航标题?
我已经创建了3个屏幕,在堆栈导航器中的createMaterialTopTabNavigator上显示为选项卡。我的问题是我不知道如何动态设置每个选项卡的标题。当前将标题设置为“欢迎”适用于所有选项卡。需要帮忙吗? xxxxxx xxxxxx xxxxxx xxxxxx xxxxxxReact native 反应导航如何动态更改每个选项卡的标题导航标题?,react-native,react-redux,react-navigation,React Native,React Redux,React Navigation,我已经创建了3个屏幕,在堆栈导航器中的createMaterialTopTabNavigator上显示为选项卡。我的问题是我不知道如何动态设置每个选项卡的标题。当前将标题设置为“欢迎”适用于所有选项卡。需要帮忙吗? xxxxxx xxxxxx xxxxxx xxxxxx xxxxxx 从“expo”导入{LinearGradient}; 从“本机基”导入{Icon}; 从“React”导入React; 从“react native”导入{StyleSheet,View}; 从“react nav
从“expo”导入{LinearGradient};
从“本机基”导入{Icon};
从“React”导入React;
从“react native”导入{StyleSheet,View};
从“react navigation”导入{createMaterialTopTabNavigator,DrawerActions};
从“../TabNavigator/Home”导入主页;
从“../TabNavigator/MyProfile”导入MyProfile;
从“../TabNavigator/SelectAirtime”导入SelectAirtime;
导出默认类TabNavigator扩展React.Component{
静态导航选项=({navigation,})=>{
返回{
标题:“欢迎”,
左校长:(
navigation.dispatch(DrawerActions.openDrawer())}/>
),
头部背景:(
),
标题样式:{color:'#fff'},
}
}
render(){
返回(
);
}
}
const HomeScreenTabNavigator=creatematerialoptabnavigator({
主页:{
屏幕:主页、导航选项:{
tabBarIcon:({tintColor})=>(),
}
},
“购买播放时间”:{
屏幕:选择播放时间、导航选项:{
tabBarIcon:({tintColor})=>(),
}
},
“账户”:{
屏幕:MyProfile,导航选项:{
tabBarIcon:({tintColor})=>(),
}
},
},
{
initialRouteName:“主页”,
tabBarPosition:'底部',
选项卡选项:{
activeTintColor:'白色',
InactiveIntColor:“#f2f2f2”,
标签样式:{
字体大小:9,
},
标签样式:{
身高:60,
},
风格:{
背景颜色:“#1e3c72”,
borderBottomColor:“#1e3c72”,
},
指标类型:{
高度:0,,
},
showIcon:没错,
}
}
)
定义选项卡导航器:
import { LinearGradient } from 'expo';
import { Icon } from "native-base";
import React from 'react';
import { StyleSheet, View } from 'react-native';
import { createMaterialTopTabNavigator, DrawerActions } from 'react-navigation';
import Home from '../TabNavigator/Home';
import MyProfile from '../TabNavigator/MyProfile';
import SelectAirtime from '../TabNavigator/SelectAirtime';
const HomeScreenTabNavigator = createMaterialTopTabNavigator({
Home: {
screen: Home,
navigationOptions: {
tabBarIcon: ({ tintColor, homeTitle }) => ( < Icon style = { { color: 'white', fontSize: 24 } } name = 'home'
type = "MaterialCommunityIcons" / > ),
tabBarLabel: homeTitle,
}
},
"Buy AirTime": {
screen: SelectAirtime,
navigationOptions: {
tabBarIcon: ({ tintColor, selectAirtimeTitle }) => ( < Icon style = { { color: 'white', fontSize: 24 } } name = 'cards-outline'
type = "MaterialCommunityIcons" / > ),
tabBarLabel: selectAirtimeTitle,
}
},
"Account": {
screen: MyProfile,
navigationOptions: {
tabBarIcon: ({ tintColor, myProfileTitle }) => ( < Icon style = { { color: 'white', fontSize: 24 } } name = 'user'
type = "EvilIcons" / > ),
tabBarLabel: myProfileTitle,
}
},
}, {
initialRouteName: 'Home',
tabBarPosition: 'bottom',
tabBarOptions: {
activeTintColor: 'white',
inactiveTintColor: '#f2f2f2',
labelStyle: {
fontSize: 9,
},
tabStyle: {
height: 60,
},
style: {
backgroundColor: '#1e3c72',
borderBottomColor: '#1e3c72',
},
indicatorStyle: {
height: 0,
},
showIcon: true,
}
})
export default HomeScreenTabNavigator;
从“expo”导入{LinearGradient};
从“本机基”导入{Icon};
从“React”导入React;
从“react native”导入{StyleSheet,View};
从“react navigation”导入{createMaterialTopTabNavigator,DrawerActions};
从“../TabNavigator/Home”导入主页;
从“../TabNavigator/MyProfile”导入MyProfile;
从“../TabNavigator/SelectAirtime”导入SelectAirtime;
const HomeScreenTabNavigator=creatematerialoptabnavigator({
主页:{
屏幕:主页,
导航选项:{
tabBarIcon:({tintColor,hometTitle})=>(),
tabBarLabel:homeTitle,
}
},
“购买播放时间”:{
屏幕:选择播放时间,
导航选项:{
tabBarIcon:({tintColor,selectairtimettitle})=>(),
tabBarLabel:选择AirTimeTitle,
}
},
“账户”:{
屏幕:MyProfile,
导航选项:{
tabBarIcon:({tintColor,myProfileTitle})=>(),
tabBarLabel:myProfileTitle,
}
},
}, {
initialRouteName:“主页”,
tabBarPosition:'底部',
选项卡选项:{
activeTintColor:'白色',
InactiveIntColor:“#f2f2f2”,
标签样式:{
字体大小:9,
},
标签样式:{
身高:60,
},
风格:{
背景颜色:“#1e3c72”,
borderBottomColor:“#1e3c72”,
},
指标类型:{
高度:0,,
},
showIcon:没错,
}
})
导出默认HomeScreenTabNavigator;
使用它:
<HomeScreenTabNavigator
screenProps={{
homeTitle: 'This home title',
selectAirtimeTitle: 'This airtime title',
myProfileTitle: 'This profile title',
}}
/>
希望对你有用
<HomeScreenTabNavigator
screenProps={{
homeTitle: 'This home title',
selectAirtimeTitle: 'This airtime title',
myProfileTitle: 'This profile title',
}}
/>