【问题标题】:How to set tabBarIcon from the state in navigationOptions (react-navigation)如何从 navigationOptions 中的状态设置 tabBarIcon (react-navigation)
【发布时间】:2017-06-04 21:06:18
【问题描述】:

我想做这样的事情。我的状态中有图像,但它显示未定义的错误。我正在使用 react-navigation 中的 tabNavigator。

static navigationOptions = {
   tabBarIcon:  <Image source={{uri: this.state.userImage}} style={{width:30, height: 30}}/>   
}

【问题讨论】:

    标签: react-native react-navigation


    【解决方案1】:

    首先你需要定义一个函数来返回你的 react 原生组件,而不是组件本身。

    static navigationOptions = {
       tabBarIcon: () => (<Image source={{uri: this.state.userImage}} style={{width:30, height: 30}}/>)
    }
    

    您看到的错误可能是因为您试图在静态方法中引用组件的实例 (this.state.userImage)

    【讨论】:

      猜你喜欢
      • 2019-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-24
      • 1970-01-01
      • 2018-04-03
      • 2018-08-13
      • 1970-01-01
      相关资源
      最近更新 更多