Segmented Control Tab in React Native for Android and iOS

This is an Example of Segmented Control Tab in React Native for Android and iOS using react-native-segmented-control-tab. iOS developers knows what Segmented Control Tab is but if you are coming from an Android development background and have no idea what Segmented Control Tab is, then just imagine a Tab View in Android. Segmented Control Tab is same as Tab in Android but without Swipe to change Tab feature.

It is used as a navigator or to show multiple screens in a single screen. There are 4 Types of Segmented Control Tab that we are going to cover:

  1. Simple Segmented Control Tab
  2. Simple Segmented Control Tab with Badges
  3. Multi Select Simple Segmented Control Tab
  4. Custom Styling Segmented Control Tab

In this example, we will see how to make a Segmented Control Tab, how to select any tab as default tab, how to call any handler when tab changes, how to control a tab selection using state. So let’s get started.

Import Segmented Control Tab using

to import Segmented Control Tab we use

To make Simple Segmented Control Tab

Simple Segmented Control Tab with Badges

Multi Select Simple Segmented Control Tab

Custom Styling Segmented Control Tab

For this example, we will make a screen with 4 different type of Segmented Control Tab. Each of Tab have different property. This 4 Segmented Control Tab include Simple Segmented Control, Additional badges in Simple Segmented Control, Simple Segmented Control with multi Select, Simple Segmented with Custom Styling.

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 SegmentedControlTab we need to install react-native-segmented-control-tab dependency.

To install this open the terminal and jump into your project using

Run the following command to install

This command will copy all the dependency into your node_module directory.

–save is optional, it is just to update the react-native-segmented-control-tab dependency in your package.json file.

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

Android

         

IOS

         


This is how you can make a Segmented Control Tab in React Native for Android and iOS using react-native-segmented-control-tab. 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. 🙂

How to Make a View Like Android Fragment in React Native

In this post, you will see How to Make a View Like Android Fragment in React Native. Developers from android development backgrounds know very well about the Fragment in Android but for those who haven’t heard about that

Android Fragment is the part of the activity, it is also known as sub-activity. There can be more than one fragment in an activity. Fragments represent multiple screens inside one activity.

There is nothing like a Fragment Component in React Native to make a view like the Android Fragment for Android and IOS. To make the fragment view we have to manage the visibility of the child view using state. In this example, I have made a state to store a number. This number will be used to return the screen we want to show using a function. 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.

Project Structure

To start with this example you need to create a directory named components in your project and create three files FirstScreen.js, SecondScreen.js, and ThirdScreen.js in it.

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

App.js

Open components/FirstScreen.js in any code editor and the Replace the code with the following code.

FirstScreen.js

Open components/SecondScreen.js in any code editor and the Replace the code with the following code.

SecondScreen.js

Open components/ThirdScreen.js in any code editor and the Replace the code with the following code.

ThirdScreen.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 to make a view like Android Fragment in React Native for Android and IOS. 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. 🙂

React Native Pass Value From One Screen to Another Using React Navigation

Passing the value from one screen to another is one of the most useful things while we have an application which needs to communicate between the different screens. We can easily pass the data between different activities easily using the this.props.navigation.navigate() which is used to navigate between different screens. In the same method, we can easily pass the value and can get it from other screens.

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.

In our example below, we will pass an input taken from the first screen to the second screen.

To pass the value between different activities

  1. Pass params to a route by putting them in an object as a second parameter to the navigation.navigate function from First Screen. Using :
  2. Read the params in your Second screen. Using:

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

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.

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.

Project File Structure

To start with this Example you need to create a directory named pages in your project and create two files FirstPge.js and SecondPage.js in it.

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

App.js

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

FirstPage.js

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

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

     

This is how you can pass the value from one screen to another screen. 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. 🙂