在反应导航 5.x 上动态更改标题标题 [英] Dynamically change header title on react navigation 5.x

查看:69
本文介绍了在反应导航 5.x 上动态更改标题标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近更新了我的项目以响应导航 5.x.在早期版本中,我们使用如下设置标题标题:

I have recently updated my project to react navigation 5.x. In earlier version we used to set header title as follows :

static navigationOptions = ({ navigation }) => ({
        title: 'find',
});

这不适用于 React Navigation 5.x.请提出建议.

This is not working on React Navigation 5.x. Please Suggest.

推荐答案

你可以通过 2 种方法来解决;

You can do it via 2 methods;

1:将 options 设置为屏幕上的变量并保留当前代码:

1: Set options to be a variable from your screen and keep your current code:

<Stack.Screen
  name="Label"
  component={Component}
  options={Component.navigationOptions}
/>

// component
static navigationOptions = {
  title: 'find',
};

2:通过在组件中使用 setOptions:

2: By using setOptions in your component:

<Stack.Screen
  name="News"
  component={News}
  options={{
    title: 'Default',
  }}
/>

// component
this.props.navigation.setOptions({title: 'find'});

这篇关于在反应导航 5.x 上动态更改标题标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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