Ask Your Question
3

How to conceal the Stack header on the home screen of React Native Expo Router?

asked 2023-06-16 23:35:13 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-06-16 23:38:02 +0000

bukephalos gravatar image

To conceal the Stack header on the home screen of React Native Expo Router, you can use the headerShown property in the options object for the screen component that represents the home screen.

Here's an example code snippet:

import React from 'react';
import { View, Text } from 'react-native';
import { createStackNavigator } from '@react-navigation/stack';

const Stack = createStackNavigator();

function HomeScreen() {
  return (
    <View>
      <Text>Home screen</Text>
    </View>
  );
}

function App() {
  return (
    <Stack.Navigator>
      <Stack.Screen
        name="Home"
        component={HomeScreen}
        options={{ headerShown: false }}
      />
       {/* Other screens */}
    </Stack.Navigator>
  );
}

export default App;

In the above code, the headerShown option is set to false for the HomeScreen component. This will hide the header for this screen only. If you want to hide the header for all screens, you can set the defaultScreenOptions property in the navigationOptions object for the StackNavigator. For example:

import React from 'react';
import { View, Text } from 'react-native';
import { createStackNavigator } from '@react-navigation/stack';

const Stack = createStackNavigator();

function HomeScreen() {
  return (
    <View>
      <Text>Home screen</Text>
    </View>
  );
}

function App() {
  return (
    <Stack.Navigator
      screenOptions={{
        headerShown: false
      }}
    >
      <Stack.Screen
        name="Home"
        component={HomeScreen}
      />
       {/* Other screens */}
    </Stack.Navigator>
  );
}

export default App;

In the above code, the screenOptions property for the StackNavigator is set to { headerShown: false }, which will hide the header for all screens.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-16 23:35:13 +0000

Seen: 11 times

Last updated: Jun 16 '23