React-native-screens: Header Component

Created on 11 Aug 2020  路  6Comments  路  Source: software-mansion/react-native-screens

Hello everyone, is it possible to have a header component and not a string?

Most helpful comment

You can always set headerShown: false and apply your own header on top of the Screen component, it does not need to be controlled by native-stack. But we are considering exposing such an option in the future.

All 6 comments

What do you mean by "string"? Headers in native-stack are native components and can only be changed by the props regarding them: https://github.com/software-mansion/react-native-screens/tree/master/native-stack#options.

Hello @WoLewicki I am testing like this:

const HomeStack = createNativeStackNavigator()

const HomeStackScreen = () => (
    <HomeStack.Navigator
        headerMode='screen'
        screenOptions={({ navigation, route }) => ({
            headerTitle: <LogoTitle navigation={navigation} route={route} />
        })}
    >
      <HomeStack.Screen name="Home" component={Home} />
      <HomeStack.Screen name="Nota" component={Nota}/>
    </HomeStack.Navigator>
)

but it does not work, like this if:

const HomeStackScreen = () => (
    <HomeStack.Navigator
        headerMode='screen'
        screenOptions={({ navigation, route }) => ({
            headerTitle: 'Header'
        })}
    >
      <HomeStack.Screen name="Home" component={Home} />
      <HomeStack.Screen name="Nota" component={Nota}/>
    </HomeStack.Navigator>
)

I am closing this issue. Let me know if the solution is not what you are looking for in order to reopen it.

@WoLewicki
There should be a header prop also (like in navigation stack)
So that we can replace the whole header instead of specifying the left right and center header.
That will be helpful

You can always set headerShown: false and apply your own header on top of the Screen component, it does not need to be controlled by native-stack. But we are considering exposing such an option in the future.

Was this page helpful?
0 / 5 - 0 ratings