简体   繁体   English

隐藏先前的标签和标题react-navigation v3

[英]Hide previous tabs and header react-navigation v3

I have a createMaterialTopTabNavigator and when I press to navigate on another screen, I would like hide the tabs and the header but display the current header ("Pronostics détails"). 我有一个createMaterialTopTabNavigator,当我按导航到另一个屏幕时,我想隐藏选项卡和标题,但显示当前标题(“ Pronosticsdétails”)。 It's possible ? 这是可能的 ?

在此处输入图片说明

The code of MontanteTab : MontanteTab的代码:

    import React from 'react';
import {ScrollView, View, FlatList} from 'react-native';
import {ListItem} from "react-native-elements";
import pronostics from "../../data/Constants/Pronostics";
import {createAppContainer, createStackNavigator} from "react-navigation";
import PronosticsDetailsScreen from "../../screens/PronosticsDetailsScreen";

class MontanteTab extends React.Component {
    render() {
        return (
            <View>
                <ScrollView>
                    <View>
                        <FlatList
                            data={pronostics}
                            keyExtractor={(item, index) => index.toString()}
                            renderItem={({item}) => (
                                <ListItem
                                    key={item.id}
                                    leftAvatar={{source: {uri: item.image}}}
                                    title={item.competition}
                                    subtitle={item.equipe_domicile + ' - ' + item.equipe_exterieur}
                                    onPress={() => this.props.navigation.navigate('PronosticsDetails', {name: 'Jnae'})}
                                />
                            )}
                        />
                    </View>
                </ScrollView>
            </View>
        );
    }
}

const MontanteStack = createStackNavigator(
    {
        Montante: {
            screen: MontanteTab,
            navigationOptions: ({navigation}) => ({
                header: null,
            }),
        },
        PronosticsDetails: {
            screen: PronosticsDetailsScreen,
            navigationOptions: ({navigation}) => ({
                headerMode: 'screen',
                headerTitle: 'Pronostics détails',
                headerStyle: {
                    backgroundColor: '#000000',
                    textAlign: 'center',
                },
                headerTintColor: '#ffffff',
                headerTitleStyle: {
                    color: '#c7943e',
                    textAlign: 'center',
                    alignSelf: 'center',
                    justifyContent: 'center',
                    flex: 1,
                }
            }),
        },
    },
    {
        initialRouteName: 'Montante',
    }
);

export default createAppContainer(MontanteStack);

The code of PronosticsDetailsScreen : PronosticsDetailsS​​creen的代码:

    import React from 'react';
import {
    StyleSheet,
    View,
} from 'react-native';
import {Text} from "react-native-elements";

export default class PronosticsDetailsScreen extends React.Component {
    render() {
        return (
            <View style={styles.container}>
                <Text>Détails</Text>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#fff',
    },
    contentContainer: {
        paddingTop: 30,
    },
    image: {
        height: 100,
        width: 100,
    }
});

I tried to set the header to "null" but the current header is also hidden.. 我试图将标题设置为“ null”,但当前标题也被隐藏。

Thank you in advance for your help 预先感谢您的帮助

Life would be easy if the API supported the ability to hide createMaterialTopTabNavigator() ! 如果API支持隐藏createMaterialTopTabNavigator()的功能,生活将会很轻松! But this option exists for bottom tabs, not top. 但是此选项存在于底部选项卡,而不是顶部选项卡。

After doing research and test, I think it is possible to hide the tabs and header. 经过研究和测试后,我认为可以隐藏选项卡和标题。 It's a matter of playing with the nested navigation. 这是玩嵌套导航的问题。 (Inspired by: https://github.com/react-navigation/react-navigation/issues/1979 and Hide parent's navigation header from the nested navigator ) (灵感来自: https : //github.com/react-navigation/react-navigation/issues/1979从嵌套导航器隐藏父级的导航头

For example: 例如:

在此处输入图片说明 在此处输入图片说明

Pushing the back button on Screen 07 will go back to Screen 06. 在屏幕07上按返回按钮将返回屏幕06。

 import React from 'react'; import { StyleSheet, Text, View } from 'react-native'; import { createStackNavigator, createAppContainer, createBottomTabNavigator, createMaterialTopTabNavigator } from 'react-navigation'; import Screen01 from './screens/Screen01'; import Screen02 from './screens/Screen02'; import Screen03 from './screens/Screen03'; import Screen04 from './screens/Screen04'; import Screen05 from './screens/Screen05'; import Screen06 from './screens/Screen06'; import Screen07 from './screens/Screen07'; const AppStackNavigator = createStackNavigator({ home: { screen: Screen01 }, flowOne: { screen: createStackNavigator({ page02: { screen: Screen02 }, page03: { screen: Screen03 }, flowTwo: { screen: createBottomTabNavigator({ page04: { screen: Screen04 }, flowThree: { screen: createMaterialTopTabNavigator({ page05: { screen: Screen05 }, page06: { screen: Screen06 }, }) } }) // end createBottomTabNavigator, end flowThree }, flowFour: createStackNavigator({ page07: {screen: Screen07} } ) // end flowFour }, { navigationOptions: {header: null} // hides header in flowOne }) }, }); const AppContainer = createAppContainer(AppStackNavigator); export default class App extends React.Component { render() { return ( <AppContainer /> ); } } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#fff', alignItems: 'center', justifyContent: 'center', }, }); 

I've got Expo demo here: https://exp.host/@project8888/NavigationDemo 我在这里有世博会演示: https//exp.host/@project8888/NavigationDemo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM