Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Header for DrawerNavigation with react-navigation

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

enter image description here

Like this (the image is fix, it's just to put a logo here)

enter image description here

like image 547
Erased Avatar asked Jun 08 '17 11:06

Erased


People also ask

How do you create a React Native header?

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.

How do I use the react navigation header buttons?

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).


2 Answers

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,
})
like image 200
madox2 Avatar answered Oct 04 '22 20:10

madox2


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> .

Header Before DrawerItems

Footer After DrawerItems:

contentComponent: props => <ScrollView><DrawerItems {...props} /><Text>Your Own Footer Area After</Text></ScrollView> .

like image 21
Saeed Heidarizarei Avatar answered Oct 04 '22 22:10

Saeed Heidarizarei