反应本机导航选项调用函数错误 [英] React native navigationOptions calling function error

查看:47
本文介绍了反应本机导航选项调用函数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

navigationOptions 中调用函数时出错.

Got an error when call a function inside navigationOptions.

static navigationOptions = {
    tabBarIcon: ({ tintColor })=> (
      <Icon name='ios-add-circle' style={{ color: tintColor}} />
    ),
    tabBarOnPress: () => {
      this.callingFun();
    },
  }

  callingFun = ()=> {
    console.log('tabBarOnPress:');
  }

错误:

推荐答案

静态方法调用是在类上进行的,而不是在实例上进行的.没有办法在静态方法中引用 this.只能使用类名访问静态方法.

Static method calls are made on the class, not on the instance. There is no way to reference this in static method. Can only reach a static method using the name of the class.

export default class MediaTab extends React.Component {
  static navigationOptions = {
    tabBarIcon: ({ tintColor })=> (
      <Icon name='ios-add-circle' style={{ color: tintColor}} />
    ),
    tabBarOnPress: () => {
      MediaTab.callingFun();
    },
  }

  static callingFun = () => {
    console.log('tabBarOnPress:');
  }
}

这篇关于反应本机导航选项调用函数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆