React Native Popup Menu – Over Flow Menu

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

If you want to start a new project with a specific React Native version, you can use the --version argument:

react-native init ProjectName --version X.XX.X
react-native init ProjectName --version react-native@next

This will make a project structure with an index file named App.js in your project directory.

Installation of Dependencies

To install the 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. –save is optional, it is just to update the dependencies in you package.json file.

CocoaPods Installation

After the updation of React Native 0.60, they have introduced autolinking so we do not require to link the library but need to install pods. So to install pods use

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

3 thoughts on “React Native Popup Menu – Over Flow Menu”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

For Query / Bug / Problem / Issues we have introduced query trackerKnow More
+