【问题标题】:React native TabNavigator navigation params反应原生 TabNavigator 导航参数
【发布时间】:2018-08-05 18:02:57
【问题描述】:

我想通过主屏幕中的按钮单击操作将路由参数发送到配置文件选项卡。下面的代码是标签导航器

  const Tabs = TabNavigator({
  [routes.HOME]: {
    screen: FeedMainScreen,
    navigationOptions: {
      tabBarLabel: tabBarLabels.HOME_TAB_LABEL,
    },
  },
  [routes.SEARCH]: {
    screen: SearchScreen,
    navigationOptions: {
      tabBarLabel: tabBarLabels.SEARCH_TAB_LABEL,
    },
  },
  [routes.PROFILE]: {
    screen: ProfileScreen,
    navigationOptions: {
      tabBarLabel: tabBarLabels.PROFILE_TAB_LABEL,
    },
  },

}

和按钮点击导航是这样的

<Button onPress={() => this.props.navigation.navigate(routes.PROFILE, { id: this.props.user._id }, null)} />

并像这样从个人资料屏幕访问参数

constructor (props) {
 super(props)
 console.log('NavPrams', this.props.navigation.state)
}

总是不明确的

【问题讨论】:

    标签: react-native react-navigation


    【解决方案1】:

    您可以使用 connect() 方法成功映射道具并在任何地方使用它们。 在编写的类中添加下面提到的代码 -

        const mapStateToProps = state => {
        return {
            user: this.props.user;
        };
    };
    export default connect(mapStateToProps, {})(className);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-17
      • 2021-03-23
      • 2017-06-09
      • 2020-11-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多