How to do it...

  1. Let's start by focusing on the Panel component. First, we need to import all the dependencies that we are going to use for this class:
import React, { Component } from 'react';import {  View,  LayoutAnimation,  StyleSheet,  Text,  TouchableOpacity,} from 'react-native';
  1. Once we have the dependencies, let's declare the defaultProps for initializing this component. In this recipe, we only need to initialize the expanded property to false:
export default class Panel extends Component {  static defaultProps = {    expanded: false  };}const styles = StyleSheet.create({  // Defined on later step});
  1. We are going to use the height property on the state object to expand or collapse the container. The first time this component gets created, ...

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.