1

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"). It's possible ?

enter image description here

The code of 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 :

    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..

Thank you in advance for your help

Valentin Harrang
  • 1,081
  • 2
  • 17
  • 34
  • Why you dont use diferente page? When you press the tab go to the new page with the layout that you need? – Manuel Eduardo Romero Dec 30 '18 at 00:47
  • The "onPress" is in the layout of the tab. For example : my screen "Pronostics" have createMaterialTopTabNavigator of 4 tabs. I press on a tab and in the layout of this tab there is "ListItem" with "onPress" attribute to go to the PronostiscDetailsScreen. You understand ? – Valentin Harrang Dec 30 '18 at 01:04

1 Answers1

2

Life would be easy if the API supported the ability to hide 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)

For example:

enter image description here enter image description here

Pushing the back button on Screen 07 will go back to Screen 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