Implementing React Navigation V2
In this recipe, we are going to learn how to implement React Navigation V2 in our React Native application. We will create a simple navigation between sections.
Getting Ready
We need to install the react-navigation
dependency:
npm install react-navigation
How to do it...
Let's implement React Navigation v2:
- Include
createDrawerNavigation
andDrawerItems
from react-navigation and the components we want to render as sections (Home and Configuration):
// Dependencies import React, { Component } from 'react'; import { StyleSheet, View, ScrollView, Image } from 'react- native'; // React Navigation import { createDrawerNavigator, DrawerItems } from 'react- navigation'; // Components import Home from './sections/Home'; import Configuration from './sections/Configuration';
File: App.js
- In CustomDrawerComponent, we will render the Codejobs logo and the menu (you can modify this as you need it):
// Custom Drawer Component // Here we are displaying the menu options...