Posts

Custom Navigation Drawer / Sidebar with Image and Icon in Menu Options

This is an example of Custom Navigation Drawer / Sidebar with Image and Icon in Menu Options with React Navigation V. 3+. We will use react-navigation to make a navigation drawer in this example. I hope you have already seen our last post on React Native Navigation Drawer as this post is the extended version of React Native Navigation Drawer.

In this example, we have a navigation drawer with 3 screens in the navigation menu. We will make the custom sidebar in place of the simple navigation drawer so that we can modify the Navigation Drawer menu options according to our need.

In the custom Sidebar, we will have a profile image and an array of option name with the icon and there targeted navigation screen. With the help of a loop and this array, we will make N number of options with icon in the Navigation Drawer.

This example will work for the React Navigation Version 3+. If you are using Version 2+ then please find the comments in the code for the suitable changes or can see our old post React Native Navigation Version 2+ for the help.

We are going to use contentComponent prop of createDrawerNavigator to set our custom view which is CustomSidebarMenu.js in this example.

To set the custom view in Navigation Drawer / Sidebar Menu

You can set your own custom sidebar too. So let’s get started with the example.

To Make a React Native App

Getting started with React Native will help you to know more about the way you can make a React Native project. We are going to use react-native init to make our React Native App. Assuming that you have node installed, you can use npm to install the react-native-cli command line utility. Open the terminal and go to the workspace and run
npm install -g react-native-cli
Run the following commands to create a new React Native project
react-native init ProjectName
This will make a project structure with an index file named App.js in your project directory.

Installation of Dependencies

To use createDrawerNavigator, createStackNavigator you need to install react-navigation and react-native-gesture-handler dependencies.

To install these dependencies open the terminal and jump into your project

Run the following commands to install React Navigation Dependencies

For the Icons, we are using react-native-elements library so to install this dependency run

This command will copy all the dependencies into your node_module directory. –save is optional, it is just to update dependencies in your package.json file.

After installing the dependencies you need to link it with your project using

After linking the dependency if you face  Could not Compile Settings File project/android/settings.gradle error while building and installing the project then you can find the solution here.

Icons for the Sidebar

As I said in this example, we have used react-native-elements library which provides a different range of icons which are very useful. You can find more Icons from here

Project Structure

To start with this example you need to create a directory named pages in your project and create three files Screen1.js, Screen2.js, Screen3.js in it for the Drawer navigation.

To have the drawer Icon in Action Bar / Header you have to make an image directory in your project and have to copy any drawer image with name drawer.png (For this example. You can change if you want but you need to change the file name in code too).

For the custom sidebar, make a file called CustomSidebarMenu.js in the project directory (not in the pages directory)

Here is the drawer.png if you want to download.

Now Open App.js in any code editor and replace the code with the following code.

App.js

Open pages/Screen1.js in any code editor and the Replace the code with the following code.

Screen1.js

Open pages/Screen2.js in any code editor and the Replace the code with the following code.

Screen2.js

Open pages/Screen3.js in any code editor and the Replace the code with the following code.

Screen3.js

Open CustomSidebarMenu.js in any code editor and the Replace the code with the following code.

CustomSidebarMenu.js

(Custom Menu with large profile Image and Options with options)

To Run the React Native App

Open the terminal again and jump into your project using.
cd ProjectName
To run the project on an Android Virtual Device or on real debugging device
react-native run-android
or on the iOS Simulator by running
react-native run-ios (macOS only).

Android

 

IOS

This is how you can make a Custom Navigation Drawer / Sidebar with Image and Icon in Menu Options with React Navigation V. 3+. If you have any doubt or you want to share something about the topic you can comment below or contact us here. There will be more posts coming soon. Stay tuned!

Hope you liked it. 🙂

Example of Bottom Sheet (Material Design) in React Native

This is an Example of Bottom Sheet (Material Design) in React Native. To make a Bottom Sheet we will use BottomSheet component provided by react-native-btr.

Bottom Sheet was firstly introduced in android material design and became very popular. Different people use bottom sheet differently but the simple example which can be seen in day to day life is when you share something. When you share any data application opens a bottom sheet to ask you “share via”. We will make the same demo with the bottom sheet in this example.

Bottom Sheet

In this example, we will make a button to open a bottom sheet which has some social icons. We will use react-native-elements to make social icons.

Social Icon

To Make a React Native App

Getting started with React Native will help you to know more about the way you can make a React Native project. We are going to use react-native init to make our React Native App. Assuming that you have node installed, you can use npm to install the react-native-cli command line utility. Open the terminal and go to the workspace and run
npm install -g react-native-cli
Run the following commands to create a new React Native project
react-native init ProjectName
This will make a project structure with an index file named App.js in your project directory.

Installation of Dependencies

For installation of the dependencies, open the terminal and jump into your project using.

Run the following commands

1. For BottomSheet component you need to install react-native-btr package.
Run the following command for the installation

2. We are going to use SocialIcon component to show the Social icons so for that you have to install react-native-elements and react-native-vector-icons dependencies.
Run the following commands for the installation

This command will copy all the dependencies into your node_module directory, You can find the directories in node_module.
–save is optional, it is just to update the dependencies in your package.json file.

Linking of Dependencies

After installing the dependencies you need to link it with your project using

After linking the dependency if you face  Could not Compile Settings File project/android/settings.gradle error while building and installing the project then you can find the solution here.

Now Open App.js in any code editor and replace the code with the following code.

App.js

To Run the React Native App

Open the terminal again and jump into your project using.
cd ProjectName
To run the project on an Android Virtual Device or on real debugging device
react-native run-android
or on the iOS Simulator by running
react-native run-ios (macOS only).

IOS

Android

          

That was the example of Bottom Sheet in React Native. If you have any doubt or you want to share something about the topic you can comment below or contact us here. There will be more posts coming soon. Stay tuned!

Hope you liked it. 🙂

React Native Popup Menu – Over Flow Menu

React Native Popup Menu – Over Flow Menu is the most common thing that we can see in the Android applications. In the initial stage popup menu can be seen in the header only, but after the introduction of the material design popup menu can be seen in many places.

You can use the popup menu if you want to provide the number of options to select but don’t want to highlight them. Most developers use them when they provide 2-3 options to select and they don’t want to use navigation drawer (Side Menu).

Popup Menu

In this example, You will see how to generate the popup menu from the header or from anywhere. So let’s get started.

To Make a React Native App

Getting started with React Native will help you to know more about the way you can make a React Native project. We are going to use react-native init to make our React Native App. Assuming that you have node installed, you can use npm to install the react-native-cli command line utility. Open the terminal and go to the workspace and run
npm install -g react-native-cli
Run the following commands to create a new React Native project
react-native init ProjectName
This will make a project structure with an index file named App.js in your project directory.

Installation of Dependencies

To install teh dependencies open the terminal and jump into your project

1. To use Menu, { MenuItem, MenuDivider } you need to install react-native-material-menu using

2. We will need React Navigator to switch from one screen to another so we will also install react-navigation and react-native-gesture-handler dependencies.

These commands will copy all the dependencies into your node_module directory, You can find the directory in node_module.
–save is optional, it is just to update the dependencies in you package.json file.

Linking of Dependencies

After installing the dependencies you need to link it with your project using

After linking the dependency if you face  Could not Compile Settings File project/android/settings.gradle error while building and installing the project then you can find the solution here.

Dependency Version for this Example used is

Project Structure

To start with this Example you need to create a directory like below screenshot:

  1. A pages directory which has another directory called component.
  2. Add two files in the Pages directory called FirstPage.js and SecondPage.js.
  3. Add two files in a component called CustomMenu.js and CustomMenuIcon.js.

App.js will have our Stack Navigator which is like an index file of our application. FirstPage.js and SecondPage.js will be the first and second screen of the application. We will use CustomMenu.js and CustomMenuIcon.js as custom popup menu components.

Now Open App.js in any code editor and replace the code with the following code.

App.js

Open FirstPage.js in any code editor and replace the code with the following code.

FirstPage.js

Open SecondPage.js in any code editor and replace the code with the following code.

SecondPage.js

Open CustomMenu.js in any code editor and replace the code with the following code.

CustomMenu.js

Open CustomMenuIcon.js in any code editor and replace the code with the following code.

CustomMenuIcon.js

To Run the React Native App

Open the terminal again and jump into your project using.
cd ProjectName
To run the project on an Android Virtual Device or on real debugging device
react-native run-android
or on the iOS Simulator by running
react-native run-ios (macOS only).

                
      

That was the React Native Popup Menu. If you have any doubt or you want to share something about the topic you can comment below or contact us here. There will be more posts coming soon. Stay tuned!

Hope you liked it. 🙂

React Native Bottom Action Menu

This is an Example to make React Native Bottom Action Menu. To make Bottom Action Menu, we are going to use ActionSheet component from react-native-actionsheet library.

This can be mostly seen by the IOS developers as it looks like default select option in IOS. With the help of Bottom Action Menu, you can provide the facility to select from multiple options.

Bottom Action Menu

To Make a React Native App

Getting started with React Native will help you to know more about the way you can make a React Native project. We are going to use react-native init to make our React Native App. Assuming that you have node installed, you can use npm to install the react-native-cli command line utility. Open the terminal and go to the workspace and run
npm install -g react-native-cli
Run the following commands to create a new React Native project
react-native init ProjectName
This will make a project structure with an index file named App.js in your project directory.

Installation of Dependency

To use ActionSheet you need to install react-native-actionsheet package. To install this

Open the terminal and jump into your project

Run the following command

This command will copy all the dependencies into your node_module directory, You can find the directory in node_module the directory named react-native-actionsheet. –save is optional, it is just to update the react-native-action sheet dependancy in your package.json file.

–save is optional, it is just to update the react-native-actionsheet dependancy in your package.json file.

Dependency Version for this Example used is

Open App.js in any code editor and replace the code with the following code.

App.js

To Run the React Native App

Open the terminal again and jump into your project using.
cd ProjectName
To run the project on an Android Virtual Device or on real debugging device
react-native run-android
or on the iOS Simulator by running
react-native run-ios (macOS only).

Android

IOS

This is how you can make React Native Button Action Menu. If you have any doubt or you want to share something about the topic you can comment below or contact us here. There will be more posts coming soon. Stay tuned!

Hope you liked it. 🙂