安装组件后更改导航栏标题

时间:2017-01-27 11:47:51

标签: react-native navigation ex-navigation

Ex-navigation允许使用静态路由定义导航栏标题

static route = {
  navigationBar: {
    title: 'title'
  }
}

我需要在安装组件后以编程方式设置navigationBar title,因为它依赖于从服务器接收的数据。我该怎么办?

我已尝试使用props.route.config,但只有在componentDidMount()中调用时才有效,但在组件生命周期中不会有效。

this.props.route.config.navigationBar.title = 'new title'

1 个答案:

答案 0 :(得分:1)

按照here in the doc所述使用updateCurrentRouteParams

class ProfileScreen extends React.Component {
  static route = {
    navigationBar: {
      title(params) {
        return `Hello ${params.name}`;
      }
    }
  }

  callMeLatter() {
    this.props.navigator.updateCurrentRouteParams({name: "Jon Doe"})
  }
}