Posts

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

Example of Tooltip in React Native for Android and IOS

This is an Example of Tooltip in React Native for Android and IOS using react-native-walkthrough-tooltip library. The Tooltip is a common graphical user interface element. It is used to show the usability of any button or any option.

In this example, we will see how to show a tooltip on a click of a button. So let’s get started.

Import Tooltip using

To Show Tooltip

For this example, we will make a screen with 1 buttons using TouchableHighlight and on the click of the button we will change the visibility state of Tootip to make it visible.

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 Tooltip we need to install react-native-walkthrough-tooltip 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-walkthrough-tooltip 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 Tooltip in React Native for Android and IOS using react-native-walkthrough-tooltip. 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 Touchable using react-native-platform-touchable

This is an Example to Make React Native Touchable using react-native-platform-touchable. We have already seen 4 Different Type of React Native Touchable in our last post in Beginner section. Here we will talk about the React Native Touchable.

React Native Touchable is built into React Native core which is a wrapper around the various Touchable* components in order to use TouchableNativeFeedback whenever possible.

If we talk about Android devices TouchableNativeFeedback  provides the Native experience but it is only supported by the Android and not supported by iOS, So in case of iOS we generally use TouchableOpacity as an alternative solution for the iOS.

In the above situation we have two choices either we use a common Touchable which is TouchableOpacity (Best for both platform) or identify the platform and then apply the Touchable accordingly. If you want to use the first method then its OK, you can proceed with that but if you want to provide the Native experience to your App users then you should go for the second one which makes the code lengthy (not much but a little bit).

react-native-platform-touchable library bought a simple component Touchable for the second case mentioned above. It is a wrapper over various Touchables which makes  the life very easy. You just have to install the dependancy and you are good to go. It will handle all the conditions and will use the Touchable according to the platform to provide the best experience.

For iOS:

TouchableOpacity with default activeOpacity.

For Android:

TouchableNativeFeedback with background from Android app style for Android API <= 20

TouchableOpacity for Android < 5.0

In this example, we will make a simple button with Touchable component to show the rendering of different Touchables according to different platform. So let’s get started.

Import using React Native Communication

To Make Touchable

For this example, we will make a home screen with 1 buttons using Touchable.

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 Touchable we need to install react-native-platform-touchable 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-platform-touchable 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 React Native Touchable using react-native-platform-touchable. 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. 🙂

Different Type of Modal Box in React Native

This is an Example of Different Type of Modal Box in React Native. We will use the Modal Component provided by react-native-modalbox. Modal Box is a React Native component which very easy and fully customizable. It has also implemented the ‘swipe down to close’ feature.

A modal is a dialog box/popup window that is displayed on top of the current page.

Modal Boxes are very useful to provide important pieces of information, to take input or to make some selection from a small chunk of data on the same screen.

In this example, we will see 7 Types of different Modal Boxes:

  1. Basic Modal.
  2. Top Modal.
  3. Center Modal with Cancel Disable/Enable.
  4. Bottom Modal.
  5. Modal Open/ Close Using State.
  6. Bottom Modal with ScrollView.
  7. Modal with Input.

Basic Modal

Top Modal

Center Modal with Cancel Disable/Enable

Bottom Modal

Modal Open/ Close Using State

Bottom Modal with ScrollView

Modal with Input

For this example, we will make a home screen with 7 different buttons to open the different types of Modals.

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 Modal we need to install react-native-modalbox 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-modalbox dependancy 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).

IOS

Android

            
      

This is how you can use Different Type of Modal Box 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. 🙂

Linear Gradient Component in React Native

This is an Example of Linear Gradient Component in React Native. For those who have no idea about Gradient, A Gradients let you display smooth transitions between two or more specified colors. The gradient can be of two types:

  • Linear Gradients (goes down/up/left/right/diagonally)
  • Radial Gradients (defined by their center)

In this example, we will see the Linear Gradient. To Make a Linear Gradient in React Native we will use LinearGradient component from @react-native-community/react-native-linear-gradient provided by react-native-community. This is very useful if you want to make a custom button with a curve effect or any multi-color background.

In this example, we will make three buttons (Note: It is not only for the buttons you can use gradient in any view) with three types of gradient background:

  1. Simple Linear Gradient.
  2. Horizontal Gradient.
  3. Location Gradient.

Simple Gradient

Horizontal Gradient

Location Gradient

Here are some additional props for knowledge:

  1. colors: An array of at least two color values that represent gradient colors. Example: [‘red’, ‘blue’] sets gradient from red to blue.
  2. start: An optional object of the following type: { x: number, y: number }. Coordinates declare the position that the gradient starts at, as a fraction of the overall size of the gradient, starting from the top left corner. Example: { x: 0.1, y: 0.1 } means that the gradient will start 10% from the top and 10% from the left.
  3. end: Same as the start, but for the end of the gradient.
  4. locations: An optional array of numbers defining the location of each gradient color stop, mapping to the color with the same index in colors prop. Example: [0.1, 0.75, 1] means that first color will take 0% – 10%, second color will take 10% – 75% and finally third color will occupy 75% – 100%.

I think this is enough for now 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 Dependency

To use LinearGradient we need to install react-native-linear-gradient 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-linear-gradient dependancy in your package.json file.

Linking of Dependency

After installing the dependency 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).

Case:

If you’re having trouble, you can point your package.json at GitHub to see if the issue has been fixed. Simply change the dependency

to get the data right from GitHub instead of npm and then npm install.

IOS

Android

This is how you can use Linear Gradient Component 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. 🙂

Make a Blur Background in React Native

This is an Example to Make a Blur Background in React Native. To Make a Blur Background in React Native we will use BlurView component from @react-native-community/blur provided by react-native-community. This is very useful if you want to make a splash screen.

In this example, we will make a simple screen with a Switch to switch between simple and blurred screen and three buttons to switch different type of blur effects. So let’s get started.

Make BlurView using

Different Type of Blur Effects:

  1. xlight: Extra Light Blur Type
  2. light: Light Blur Type
  3. dark: Dark Blur Type
  4. extraDark: Extra Dark Blur Type(tvOS only)
  5. regular: Regular Blur Type (iOS 10+ and tvOS only)
  6. prominent: Prominent Blur Type (iOS 10+ and tvOS only)

Adjust Blur Intensity:
0-100 – Adjusts Blur Intensity
Note: The maximum blur amount on Android is 32, so higher values will be clamped to 32.

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 BlurView we need to install @react-native-community/blur 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-community/blur dependancy in your package.json file.

Linking of Dependency

After installing the dependency 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.

Note: Please add the following lines for Android

(Android only) Add the following to android/app/build.gradle

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

         

This is how you can Make a Blur Background 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. 🙂

Tab View inside Navigation Drawer / Sidebar with React Navigation

This is an example of Tab View inside Navigation Drawer / Sidebar with React Navigation in React Native. We will use react-navigation to make a navigation drawer and Tab in this example. I hope you have already seen our post on React Native Navigation Drawer because in this post we are just extending the last post to show the Tab View inside the Navigation Drawer.

In this example, we have a navigation drawer with 3 screens in the navigation menu and a Tab View on the first screen of the Navigation Drawer. When we open Screen1 the Tab will be visible and on the other options, this Tab will be invisible.

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.

To Create a DrawerNavigator

To Create Material Top Tab Navigator

In this example, we will make a Tab Navigator inside a Drawer Navigator 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 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

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.

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, and Screen3.js. This files will be the Navigation Screens of the Drawer Navigator.

We will create a Tab in Screen1 so we will make a directory called TabPages inside pages directory and will create 3 files HomeScreen.js, SettingScreen.js, and TabHelper.js.

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

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 replace the code with the following code.

Screen1.js

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

Screen2.js

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

Screen3.js

Open pages/TabPages/TabHelper.js in any code editor and replace the code with the following code.

TabHelper.js

Open pages/TabPages/HomeScreen.js in any code editor and replace the code with the following code.

HomeScreen.js

Open pages/TabPages/SettingsScreen.js in any code editor and replace the code with the following code.

SettingsScreen.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 add Tab View inside Navigation Drawer / Sidebar with React Navigation 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. 🙂

How to Hide Navigation Option from Navigation Drawer / Sidebar

This post is about How to Hide Navigation Option from Navigation Drawer / Sidebar in React Native. 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 because in this post we are just extending the last post to hide the navigation option from the Navigation Drawer.

Hide Navigation Drawer option means while creating navigation drawer we have a screen in our navigation drawer which should be visible in the navigation option in the left menu but with some changes, we can also control the visibility of the option.

This option is very useful when you have to manage the visibility of the options while the user is logged in or logged out.

In this example, we have a navigation drawer with 4 screens but only 3 navigation option available in the Drawer Menu. On the first screen, we will have a button to open a screen which is a part of the navigation drawer but it is not visible in the Drawer Menu options.

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.

To Hide the Navigation Option from the Navigation Drawer

To hide the navigation option from the Navigation Drawer we have to return a custom drawer label. Have a look in the code snippet below.

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

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.

Project Structure

To start with this example you need to create a directory named pages in your project and create four files Screen1.js, Screen2.js, Screen3.js, HiddenScreen.js in it.

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

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 replace the code with the following code.

Screen1.js

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

Screen2.js

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

Screen3.js

Open pages/HiddenScreen.js in any code editor and replace the code with the following code.

HiddenScreen.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 Hide Navigation Option from Navigation Drawer / Sidebar 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. 🙂

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)