Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

{headerShown: false} doesn't affect to the screen in react native expo

In my applikation are soem Stack Navigation and a Tab Navigation. Everywhere in my app i disabled the header. But in one screen the headerShown: false doesn’t affect to the screen and is still visible including backarrow and white background.

I don’t have that much experience with react native navigation. I can imagine that I have a fundamental error in the structure of my app navigation.

Preview

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { createStackNavigator } from '@react-navigation/stack';
import CreateScreen from './screens/CreateScreen';
import HomeScreen from './screens/HomeScreen';
import JoinScreen from './screens/JoinScreen';
import SettingsScreen from './screens/SettingsScreen';
import LoginScreen from './screens/LoginScreen';
import EventScreen from './screens/EventScreen';
import CamScreen from './screens/CamScreen';
import { MaterialIcons } from '@expo/vector-icons';

const Stack = createStackNavigator();
const Tab = createBottomTabNavigator();

function EventStack() {
    return (
        <Stack.Navigator >
            <Stack.Screen options={{ headerShown: false }} name="HomeScreen" component={HomeScreen} />
            <Stack.Screen options={{ headerShown: false }, ({ route }) => ({ title: route.params.eventData.eventtitle })} name="EventScreen" component={EventScreen} />
        </Stack.Navigator>
    );
}

function JoinStack() {
    return (
        <Stack.Navigator>
            <Stack.Screen options={{ headerShown: false }} name="JoinScreen" component={JoinScreen} />
            <Stack.Screen options={{ headerShown: false }, ({ route }) => ({ title: route.params.eventData.eventtitle })} name="EventScreen" component={EventScreen} />
        </Stack.Navigator>
    );
}

function CreateStack() {
    return (
        <Stack.Navigator >
            <Stack.Screen options={{ headerShown: false }} name="CreateScreen" component={CreateScreen} />
            <Stack.Screen options={{ headerShown: false }} name="EventScreen" component={EventScreen} />
        </Stack.Navigator>
    )
}

function SettingsStack() {
    return (
        <Stack.Navigator>
            <Stack.Screen options={{ headerShown: false }} name="SettingsScreen" component={SettingsScreen} />
            <Stack.Screen options={{ headerShown: false, tabBarVisible: false }} name="LoginScreen" component={LoginScreen} />
        </Stack.Navigator>
    )
}

function BottomTabs() {
    return (
        <Tab.Navigator
            screenOptions={({ route }) => ({
                tabBarIcon: ({ focused, color, size }) => {
                    let icon;
                    // TODO: Switch Icon Set to filled (active) & outline
                    if (route.name === 'Events') {
                        icon = focused ? 'list' : 'list';
                    } else if (route.name === 'CheckIn') {
                        icon = focused ? 'login' : 'login';
                    } else if (route.name === 'Cam') {
                        icon = focused ? 'camera' : 'camera';
                    } else if (route.name === 'Erstellen') {
                        icon = focused ? 'edit' : 'edit';
                    } else if (route.name === 'Einstellungen') {
                        icon = focused ? 'settings' : 'settings';
                    }
                    return (<MaterialIcons name={icon} size={size} color={color} />);
                },
                tabBarActiveTintColor: '#22d3ee',
                tabBarHideOnKeyboard: true,
                tabBarStyle: { backgroundColor: '#0f172a' },
            })}
        >
            <Tab.Screen name="Events" component={EventStack} options={{ headerShown: false }} />
            <Tab.Screen name="CheckIn" component={JoinStack} options={{ headerShown: false }} />
            <Tab.Screen name="Cam" component={CamScreen} options={{ headerShown: false }} />
            <Tab.Screen name="Erstellen" component={CreateStack} options={{ headerShown: false }} />
            <Tab.Screen name="Einstellungen" component={SettingsStack} options={{ headerShown: false }} />
        </Tab.Navigator>
    )
}

export default () => (
    <NavigationContainer>
        <Stack.Navigator>
            <Stack.Screen options={{ headerShown: false, tabBarVisible: false }} name="LoginScreen" component={LoginScreen} />
            <Stack.Screen options={{ headerShown: false }} name="BottomTabs" component={BottomTabs} />
        </Stack.Navigator>
    </NavigationContainer>
);

Thank you for your time trying to help me.

>Solution :

If you want to hide the header from every screen then define headerShown: false in screenOptions in Screen.Navigator.

<Stack.Navigator screenOptions={{headerShown: false}}>
     .....
</Stack.Navigator>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading