I am using react navigation. I want to show drawer over the header of the screen. Currently my header is not hiding below drawer when I open the drawer.
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
import { createStackNavigator, createDrawerNavigator } from 'react-navigation';
import CategoryScreen from './CategoryScreen';
import ProductsScreen from './ProductsScreen';
import CartScreen from './CartScreen';
const drawerScreens = createDrawerNavigator ({
Category: CategoryScreen,
Products: ProductsScreen,
},{
initialRouteName: 'Category'
}
)
export default AppStack = createStackNavigator(
{
drawer: {
screen: drawerScreens,
navigationOptions: ({ navigation }) => ({
header: <View style={styles.container}><Text>Header</Text></View>
}),
},
cart: {screen: CartScreen}
},
{
initialRouteName: 'drawer',
}
);
const styles = StyleSheet.create({
container: {
height: 100,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'orange',
}
})
So how to show the header which is overlaped or covered with drawer of drawer navigation.
Currently its look like this
headerShown Whether to show or hide the header for the screen. The header is shown by default. Setting this to false hides the header.
CategoryScreen
and ProductScreen
CategoryScreen
and ProductScreen
navigation optionsHere is what i meant
// wrap your screen inside the drawer into StackNavigator
const CategoryNavigator = createStackNavigator({
CategoryList: {
screen: CategoryScreen,
navigationOptions: {
title: "Category",
header: // any custom header here
}
},
});
const drawerScreens = createDrawerNavigator({
Category: CategoryNavigator,
Products: ProductNavigator,
}, {
initialRouteName: 'Category'
})
export default AppStack = createStackNavigator({
drawer: {
screen: drawerScreens,
},
cart: {
screen: CartScreen
}
}, {
initialRouteName: 'drawer',
});
This is the result
Following will make a floating header which similar with your screenshot
Set the header mode to float
(you don't need to wrap CategoryScreen
and ProductScreen
into StackNavigator
)
export default AppStack = createStackNavigator({
drawer: {
screen: drawerScreens,
},
cart: {
screen: CartScreen
}
}, {
headerMode: 'float', // set this header mode to float so you can share the header
initialRouteName: 'drawer',
});
This is the result if you change the header mode to float
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With