Create Gradient Shade Effect Button in React Native Android iOS Example

Gradient effect is a smoothly color changeable effect on a particular defined location with fix height and width. Gradient is common between all type of developer who wish to make their app or websites looks better then others. So in this tutorial we would going to create a react native app with Gradient Shade Effect Button using react-native-linear-gradient GitHub library and wrap the button with TouchableOpacity to make the gradient button clickable.

There are basically 2 types of gradient effects available in react native :

  1. Linear Gradient(Top to bottom, Bottom to top, Left to right, right to Left and Diagonally).
  2. Radial Gradient(Defined different center color).

Contents in this project Create Gradient Shade Effect Button in React Native Android iOS App Example:

1. We are using the react-native-linear-gradient GitHub npm library in our this project because there are no certain method available in react native to make the Gradient Shade Effect. So open your project name folder in command prompt and run the 
npm install reactnativelineargradient save command inside it to install this library. See the below screenshot for more details .


Screenshot of CMD / Terminal after successfully installed the library :

2. After done installation execute the 
reactnative link command. This command would refresh the whole project and index the newly installed modules in react native’s own library.

3. Import StyleSheet, View, TouchableOpacity, Text and Alert command in your project.

4. Import the LinearGradient module from react-native-linear-gradient library in your project.

5. Create a function named as SampleFunction() in your class. We would call this function on Gradient button click.

6. Create a Root View in render’s return block.

7. Now finally we would create 2 types of Gradient shade effect button in Root View. We would wrap the LinearGradient component in TouchableOpacity to make the LinearGradient clickable.

8. Create Style for LinearGradient, Root View and Text component.

9. Complete source code for App.js File :

Screenshot in Android device :

Gradient Shade Effect Button Screenshot in iOS device :