Header title is empty in TabNavigation

﹥>﹥吖頭↗ 提交于 2019-12-06 15:02:16

问题


Header title seems to not work as expected.

I already updated react-native and all other dependencies to their latest version and reviewed react-navigation documentation. Also I created a bug on github for this item.

Can you please take a look if I doing something wrong? I need to have header title set when i am using TabNavigation

const RootNavigator = createStackNavigator({
    ...publicScreens,
    Private: {
        screen: PrivateNavigator
    }
}, publicScreensConfig);

const privateScreens = {
    ContactList: {
        screen: ContactList
    },
    Settings: {
        screen: Settings
    }
};

.....

export default createBottomTabNavigator( privateScreens, options );
import React, { Component } from 'react'
import { Text, View } from 'react-native'
import GlobalColors from '../../config/colors';

export default class Settings extends Component {
    static navigationOptions = {
        title: 'Settings',
        headerStyle: {
            backgroundColor: GlobalColors.grayDark,
        },
        headerTintColor: 'white',
        headerTitleStyle: {
            fontWeight: 'bold',
        },
        gesturesEnabled: false,
    }

    render() {
        return (
            <View>
        <Text> Settigs </Text>
      </View>
        )
    }
}

But I see empty header title in the header pane. I want to see header text that come from navigation Options


回答1:


Thanks to JinHoSo answer is here

const bottomTabNavigator = createBottomTabNavigator(...)

bottomTabNavigator.navigationOptions = ({navigation, screenProps}) => {
  const childOptions = getActiveChildNavigationOptions(navigation, screenProps)
  return {
    title      : childOptions.title,
    headerLeft : childOptions.headerLeft,
    headerRight: childOptions.headerRight,
  }
}


来源:https://stackoverflow.com/questions/53915174/header-title-is-empty-in-tabnavigation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!