I'm on ReactNative and i'm using native-base and react-navigation npm.
I got this and my question is how I can have a header, up to the button "Home", I looked into the documentation of react-navigation but it's not really cleared.
https://github.com/react-community/react-navigation/blob/master/docs/api/navigators/DrawerNavigator.md
Like this (the image is fix, it's just to put a logo here)
To configure the header bar of a React Native application, the navigation options are used. The navigation options are a static property of the screen component which is either an object or a function. headerTitle: It is used to set the title of the active screen. headerStyle: It is used to add style to the header bar.
The most common way to interact with a header is by tapping on a button either to the left or the right of the title. Let's add a button to the right side of the header (one of the most difficult places to touch on your entire screen, depending on finger and phone size, but also a normal place to put buttons).
You can implement custom content component for drawer. There you can also simply render navigation items using DrawerItems
. For example:
import React from 'react'
import { Text, View } from 'react-native'
import { DrawerItems, DrawerNavigation } from 'react-navigation'
const DrawerContent = (props) => (
<View>
<View
style={{
backgroundColor: '#f50057',
height: 140,
alignItems: 'center',
justifyContent: 'center',
}}
>
<Text style={{ color: 'white', fontSize: 30 }}>
Header
</Text>
</View>
<DrawerItems {...props} />
</View>
)
const Navigation = DrawerNavigator({
// ... your screens
}, {
// define customComponent here
contentComponent: DrawerContent,
})
For Drawer Navigation, you Can add Your own Header & Footer and Make Your Own Styles with contentComponent
Config:
First import { DrawerItems, DrawerNavigation } from 'react-navigation'
Then
Header Before DrawerItems
:
contentComponent: props => <ScrollView><Text>Your Own Header Area Before</Text><DrawerItems {...props} /></ScrollView>
.
Footer After DrawerItems
:
contentComponent: props => <ScrollView><DrawerItems {...props} /><Text>Your Own Footer Area After</Text></ScrollView>
.
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