我想我凝视了太久了,现在我的大脑不起作用了。我有mobx商店,其中一个商店提供基本的主题颜色值。我想将其传递给我的“反应导航”选项卡背景色,但是我不知道该怎么做。我们正在使用Typescript,这可能会使我感到困惑,因为每次我尝试注入自己的商店时,都会遇到很多错误。
无论如何,如果有人可以帮助我弄清楚如何正确地注入商店或将道具传递给我的createMaterialTopTabNavigator函数,我将不胜感激。
这是我的顶部标签导航器代码:
export const SignedInWithGroup = createMaterialTopTabNavigator(
{
Home: {
screen: MeetingStack,
navigationOptions: {
tabBarLabel: 'Advocacy Day',
tabBarIcon: <Ionicons name="md-home" size={24} />,
},
},
Legislators: {
screen: Legislators,
navigationOptions: {
tabBarLabel: 'Legislators',
tabBarIcon: <Ionicons name="ios-people" size={24} />,
},
},
Messages: {
screen: Messages,
navigationOptions: {
tabBarLabel: 'Messages',
tabBarIcon: <Ionicons name="ios-chatboxes" size={24} />,
},
},
Directory: {
screen: DirectoryStack,
navigationOptions: {
tabBarLabel: 'Directory',
tabBarIcon: <MaterialIcons name="contacts" size={24} />,
},
},
More: {
screen: MoreStack,
navigationOptions: {
tabBarLabel: 'More',
tabBarIcon: <MaterialIcons name="more" size={24} />,
},
},
},
{
tabBarPosition: 'bottom',
tabBarOptions: {
showIcon: true,
style: {
paddingTop: Platform.OS === 'android' ? 0 : 0,
backgroundColor: "#CCBE00", //Replace with theme color
},
tabStyle: {
padding: 0,
},
labelStyle: {
marginTop: Platform.OS === 'ios' ? 8 : 0,
marginBottom: Platform.OS === 'ios' ? 20 : 10,
marginLeft: 15,
fontSize: 7,
color: 'white',
},
},
}
);
export const createRootNavigator = (props:any, signedIn = false) => {
console.log("Props");
console.log(props);
return createSwitchNavigator(
{ SignedInWithGroup: { screen: SignedInWithGroup }, SignedOut },
{ initialRouteName: signedIn ? 'SignedInWithGroup' : 'SignedOut' }
);
};
这是我的app.js中的内容:
const Layout = createRootNavigator(signedIn);
return (
<Provider {...stores}>
<Layout />
</Provider>
);
答案 0 :(得分:2)
使用MaterialTopTabBar
中的自定义标签栏。
安装react-navigation-tabs
模块。因为,反应导航的TabNaviagtion
来自react-navigation-tabs
。 (srcs)
$毛线安装react-navigation-tabs
或
$ npm install react-navigation-tabs
-保存
使您的自定义标签栏组件遵循商店(MobX)的tabBarComponent
选项。我没有编写与MobX或Redux相关的代码。
import React, { Component } from 'react';
import { MaterialTopTabBar } from 'react-navigation-tabs';
// create a component
class TabBar extends Component {
render() {
return (
<MaterialTopTabBar
{...this.props}
style={{ backgroundColor: 'green' }} // Replace with theme color. You should use observing variable from MobX or Redux.
/>
);
}
}
//make this component available to the app
export default TabBar;
createMaterialTopTabNavigator
中应用您的自定义标签栏。
const TabNavigation = createMaterialTopTabNavigator(
{
Home: HomeScreen,
Login: HomeScreen,
Register: HomeScreen,
},
{
tabBarComponent: (props) => { // Use your custom tabbar here.
return (
<TabBar
{...props}
/>
);
},
tabBarPosition: 'bottom',
tabBarOptions: {
showIcon: true,
style: {
paddingTop: Platform.OS === 'android' ? 0 : 0,
},
tabStyle: {
padding: 0,
},
labelStyle: {
marginTop: Platform.OS === 'ios' ? 8 : 0,
marginBottom: Platform.OS === 'ios' ? 20 : 10,
marginLeft: 15,
fontSize: 7,
color: 'white',
},
},
}
);
正如我所写,react-navigation-tabs
基本上在TabNavigation
中用作react-navigation
,并且当您tabBarComponent
您可以使用一些用法说明。
因此,扩展组件或从BottomTabBar
或MaterialTopTabBar
制作自定义标签栏是一种简便的解决方案。