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.
In my case, i make my own Header component and use it in each page i want. it enabled me to customize header with each page.
Absolutely it is the back door way and i hope other people have the exact answer of your question.
This is an example...
Home page:
export default class Home extends Component {
render() {
return (
<View style={{ flex: 1 }}>
<Header showBorder={true}/>
<ScrollView>
...
</ScrollView>
</View>
);
}
}
Header Component:
export default class Header extends React.PureComponent {
renderTitle = () => {
if (this.props.title) {
return (
<View style={{ flexDirection: 'column', flex: 3, justifyContent: 'center' }}>
<View style={{ alignSelf: 'flex-start' }}>
<Text style={[styles.fontBold, { fontSize:17, color: colors.borderWidthColor }]}>{this.props.title}</Text>
</View>
</View>
)
}
}
renderBack = () => {
if (this.props.back) {
return (
<View style={{ marginTop:3 }}>
<TouchableOpacity
onPress={() => {
this.props.navigation.goBack()
}}
style={{ alignSelf: 'flex-start' }}>
<Icon name="md-arrow-back" size={23} color="black" />
</TouchableOpacity>
</View>
)
}
}
render() {
return (
<View style={[{ height: 70, backgroundColor: this.props.backgroundColor, width: win.width, borderBottomWidth: this.props.showBorder ? 1 : 0 }]}>
<View style={{ flex: 1, flexDirection: 'row', marginTop: Platform.OS == 'ios' ? 17 : 3 }}>
<View style={{ flexDirection: 'column', flex: 1, justifyContent: 'center', marginLeft: 12 }}>
{this.renderBack()}
{this.renderTitle()}
</View>
</View>
</View>
)
}
}
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