Custom drawer in react native(drawer navigator)

Run the following command with your project directory

    npm i react-navigation-drawer   
    npm i react-navigation   
    npm i react-navigation-tab   

project structure

    src
        ->actions
        ->common
        ->components
        ->containers
        ->navigation
            -index.js
            -customDrawer.js
        ->reducers
        ->services
        ->store

Code for custom drawer in react native

    Open index.js in navigation folder and replace the code with the following code

index.js

import React from 'react';
import { createAppContainer, createSwitchNavigator } from "react-navigation";
import { createDrawerNavigator } from 'react-navigation-drawer';
import { createStackNavigator } from 'react-navigation-stack';

import CustomDrawer from "./CustomDrawer";
import Example from './containers/Example';

const SettingsStack = createStackNavigator({
    SettingsList: {
        screen: Example,
        navigationOptions: {
            headerTitle: 'Settings List',
        },
    },
    Profile: {
        screen: Example,
        navigationOptions: {
            headerTitle: 'Profile',
        },
    },
});

const HomeStack = createStackNavigator({
    Feed: {
        screen: Example,
        navigationOptions: {
            tabBarLabel: 'Feed',
        },
    },
    Search: {
        screen: Example,
        navigationOptions: {
            tabBarLabel: 'Search',
        },
    },
});

const MyDrawerNavigator = createDrawerNavigator({ 
    Home: HomeStack, 
    Settings: SettingsStack,
},{
    contentComponent: props => <CustomDrawer {...props} />
}) 

const AppContainer = createAppContainer(MyDrawerNavigator);

export default AppContainer;

CustomDrawer.js

import React, { Component } from 'react';
import { SafeAreaView, View, Image, ScrollView } from 'react-native';
import { DrawerItems } from 'react-navigation-drawer';

export default CustomDrawer = props => {
        return(
            <SafeAreaView style={{flex:1}}>
                <View>
                    <Text style={{textAlign: 'center'}}>Welcome to custom drawer</Text>
                </View>
                <ScrollView>
                    <DrawerItems {...props} />
                </ScrollView>
            </SafeAreaView>
        )
}

Comments

Popular posts from this blog

React Native Floating Label Textinput

React Native Tab View

React Native Modal box