如何将mapStateToProps / redux添加到react-navigation TabNavigator?

时间:2018-02-27 14:18:59

标签: javascript react-native react-router react-navigation tabnavigator

我想构建一个非常简单的示例:https://reactnavigation.org/docs/tab-based-navigation.html

import React from 'react';
import { Text, View } from 'react-native';
import { TabNavigator } from 'react-navigation'; // 1.0.0-beta.27

class HomeScreen extends React.Component {
  render() {
    return (
      <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
        <Text>Home!</Text>
      </View>
    );
  }
}

class SettingsScreen extends React.Component {
  render() {
    return (
      <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
        <Text>Settings!</Text>
      </View>
    );
  }
}

export default TabNavigator({
  Home: { screen: HomeScreen },
  Settings: { screen: SettingsScreen },
});

我如何在mapStateToProps(或任何堆栈导航器)中包装标签导航器。例如,如果我想为特定选项卡使用动态选项卡名称。

感谢。

1 个答案:

答案 0 :(得分:0)

 const MainRoot =(props) => {
      const myTabbar = TabNavigator({
              Home: LoginForm,
              Settings: RegistrationForm,
              third: TabsView
               },{
               initialRouteName: props.myName
               }
             );
       return <CustomTabNavigator/>;
 }
 const mapStateToProps = state => ({
          myName: state.LibraryMain,
 });
export default connect(mapStateToProps)(MainRoot)