How to do it...

  1. Let's start with the Button/index.js file. First, we'll import all the dependencies for this component:
import React, { Component } from 'react';import {  ActivityIndicator,  LayoutAnimation,  StyleSheet,  Text,  TouchableOpacity,  View,} from 'react-native';
  1. We're going to use only four props for this component: a label, a loading Boolean to toggle displaying either the loading indicator or the label inside the button, a callback function to be executed when the button is pressed, and custom styles. Here, we'll init the defaultProps for loading to false, and the 
    handleButtonPress to an empty function:
export default class Button extends Component {  static defaultProps = {    loading: false,    onPress: () => {},  }; // Defined ...

Get React Native Cookbook - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.