6

I have a StackNavigation and want a default Header (component Header) and want that "deep pages" shows up with the default header generated for the React Navigation.

In my index page **Index**, just wanted the Header component(first header)...but shows up another blank header:

enter image description here

In my "deep page" **Teste** just want the title and back button autogenarated by RNav(second header)...but the first header shows up.

enter image description here

This is my nav config:

const RootNavigator = StackNavigator({
    Welcome: {screen: Welcome},
    User: {
        screen: TabNavigator({
            Clientes: {
                screen: StackNavigator({
                    Index: {screen: Clientes},
                    Teste: {
                        screen: Teste,
                        header: undefined
                    }
                }, {
                    header: null,
                    navigationOptions: {
                        tabBarIcon: () => (
                            <Icon name="list-alt" size={22} color="#ffffff" />
                        )
                    }
                })
            },
            Opcoes: { screen: Opcoes }
        }, {
            tabBarPosition: 'bottom',
            tabBarOptions: {
                showLabel: false,
                activeTintColor: '#fff',
                showIcon: true,
                inactiveTintColor: '#ccc',
                indicatorStyle: {
                    backgroundColor: '#ccc'
                },
                style: {
                    backgroundColor: '#536878'
                }
            }
        })
    },
}, {
    initialRouteName: 'User',
    navigationOptions: {
        header: props => <Header {...props} />
    }
});

export default RootNavigator;
4

1 回答 1

2

每个 StackNavigator 都会带一个标题,第一个是 from RootNavigator = StackNavigator({,底部是 from Clientes: { screen: StackNavigator({

首先,header: null你的接缝Clientes: { screen: StackNavigator({没有任何影响。您应该尝试一下headerMode: 'none',这将删除空白标题,Index但也会Teste使用标题和后退按钮从标题中删除,这并不能解决您的所有问题。

所以我会建议不同的导航器结构:

RootNavigator(StackNavigator)
- Welcome
- Index
- Teste
- User(TabNavigator)
    - Clientes 
    - Opcoes

接下来你应该为Teste内部组件本身设置不同的标题(默认一个,带有后退按钮),如下所示:

import { Header } from 'react-navigation';

Teste.navigationOptions = ({ navigation, screenProps }) => ({
    return {
        header: <Header {...screenProps} {...navigation} />
    }
});

您甚至可以制作自己的标题组件并在 Teste.navigationOptions 中使用它。

于 2017-11-28T08:19:01.930 回答