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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.