YouTube Courses - Learn Smarter

YouTube-Courses.site transforms YouTube videos and playlists into structured courses, making learning more efficient and organized.

Building a Meditation App with React Native and Expo: An Educational Guide



This chapter provides a comprehensive guide to building a simple meditation application using React Native and Expo, based on a video tutorial by Steven Garcia. This educational text aims to transform the tutorial into a structured learning resource, suitable for individuals looking to enhance their mobile development skills.

1. Introduction to the Meditation App Project

This project focuses on developing a mobile meditation application using a modern JavaScript-based ecosystem. The course, taught by Steven Garcia, leverages a powerful combination of technologies to create a functional and aesthetically pleasing app.

Key Technologies Used:

  • React Native: A JavaScript framework for building native mobile applications.
  • Expo: A framework and platform for universal React applications.
  • TypeScript: A superset of JavaScript that adds static typing.
  • NativeWind: A utility-first CSS framework for React Native, using Tailwind CSS syntax.

The application built in this course features:

  • Splash Screen: A visually engaging initial screen displayed while the app loads.
  • Home Screen: A welcoming screen with a “Get Started” button.
  • Meditation Previews Screen: A scrollable list of meditation options, each with a preview image and title.
  • Meditation Session Screen:
    • Adjustable meditation duration using a modal interface.
    • Countdown timer to track meditation time.
    • Background music playback during meditation.
  • Positive Affirmations Screen:
    • Categorized affirmations displayed horizontally.
    • Scrollable affirmations within each category.
    • Visually appealing linear gradient backgrounds.

This project is designed to showcase the practical application of web development skills in a mobile context, bridging the gap between HTML, CSS, JavaScript, and mobile app development.

2. Prerequisites and Course Level

Before embarking on this project, it’s crucial to understand the required prior knowledge. This course is not beginner-friendly and assumes a solid foundation in web development fundamentals.

Required Skills:

  • Web Development Fundamentals: A strong understanding of core web technologies is essential.
    • HTML5 & CSS3: For structuring content and styling the application’s user interface.
    • JavaScript: For implementing application logic and interactivity.
  • React: Familiarity with React concepts, including components, JSX, state management, and props.
  • Tailwind CSS: Understanding the utility-first CSS approach and Tailwind CSS syntax will be beneficial for styling with NativeWind.

React A JavaScript library for building user interfaces or UI components. It allows developers to create reusable UI components and manage complex UIs efficiently.

Tailwind CSS A utility-first CSS framework that provides pre-defined CSS classes to rapidly style web elements. It emphasizes speed and customization through composition of utility classes.

Recommended Beginner Courses (by Steven Garcia):

For those lacking the prerequisite knowledge, Steven Garcia recommends his beginner-friendly courses available on stepcraft.com, including:

  • HTML5 and CSS3 Fundamentals
  • Command Line Basics
  • JavaScript Pro
  • TypeScript Mastery
  • Tailwind CSS Mastery
  • React Mastery
  • Expo React Native

3. Setting Up Your Development Environment

To build the meditation app, you need to configure your development environment with the necessary software and tools.

3.1. Software Installation

  • Xcode (for iOS Simulator on macOS):
    • Navigate to the App Store on your macOS system.
    • Search for Xcode.
    • Install Xcode. This is a large application and may take approximately 30 minutes to download.
    • After installation, open Xcode, go to Xcode > Settings > Locations.
    • Ensure that Command Line Tools are installed.
    • To launch the iOS Simulator, go to Xcode > Open Developer Tool > Simulator. You can also create new simulators via File > New Simulator.

Xcode Apple’s Integrated Development Environment (IDE) for macOS, used primarily for developing software for Apple platforms including iOS, macOS, watchOS, and tvOS. It includes tools for coding, debugging, and UI design.

  • Android Studio (for Android Emulator):
    • Visit developer.android.com/studio.
    • Download and install Android Studio.
    • Open Android Studio, click on More Actions > SDK Manager.
    • In the SDK Manager, under Android SDK, install the latest Android version (e.g., Android 14).
    • Under SDK Tools, ensure the following are checked and installed:
      • Android Emulator
      • Android SDK Platform-Tools
      • Intel Emulator Accelerator (if applicable to your processor)
    • Click Apply to install selected components.

Android Studio Google’s Integrated Development Environment (IDE) specifically designed for Android app development. It provides tools for coding, debugging, performance analysis, and emulator management for Android devices.

  • Expo Go (Mobile App for Testing):
    • Download Expo Go from the App Store (iOS) or Google Play Store (Android) on your mobile device. This app allows you to run Expo applications directly on your physical device by scanning a QR code during development.

Expo Go A free mobile application provided by Expo that allows developers to run and test Expo-built React Native applications directly on physical iOS and Android devices during development.

3.2. Project Setup and Dependencies

  1. Clone the GitHub Repository:

    • The GitHub repository for this course contains starter code, assets, and instructions. The link is provided in the video description (and typically found with YouTube videos).
    • Clone the repository to your local machine using Git: git clone [repository URL].
  2. Install Project Dependencies:

    • Navigate into the cloned project directory in your terminal: cd [project directory name].
    • Install project dependencies using npm (Node Package Manager) or yarn: npm install or yarn install. This command reads the package.json file and installs all listed packages required for the project.

npm (Node Package Manager) The default package manager for Node.js. It is used to install, manage, and share JavaScript packages. npm install command downloads and installs packages listed in the package.json file.

yarn Another popular package manager for JavaScript, also used for managing project dependencies. It is often seen as faster and more consistent than npm. yarn install performs a similar function to npm install.

  1. Download Assets:

    • Access the Google Drive link provided in the video description to download project assets (images, fonts, audio files, logo).
    • Download the .zip file and extract its contents.
    • Copy the extracted folders (images, fonts, audio, logo) into the assets directory of your project.
  2. Explore Project Files (Optional - VS Code in Browser):

    • In your project directory within your file explorer, press the period (.) key. This shortcut (on macOS and some other systems) can open the project directly in Visual Studio Code within your web browser, providing a quick way to view project files without cloning.

3.3. Visual Studio Code (VS Code) Extensions and Settings

Visual Studio Code (VS Code) is a highly recommended code editor for React Native and Expo development. Installing specific extensions can significantly enhance productivity.

Recommended VS Code Extensions:

  • Prettier - Code formatter: Automatically formats code to maintain consistent style.
  • ES7+ React/Redux/React-Native snippets: Provides code snippets for faster React and React Native development.
  • Expo Tools: Enhances Expo development experience with specific commands and features.
  • React Native Tools: Provides debugging and development tools for React Native.
  • Tailwind CSS IntelliSense: Offers autocompletion, syntax highlighting, and other features for Tailwind CSS within VS Code.
  • VS Code Icons (Optional): Improves visual file and folder icons within VS Code.

Installing Extensions:

  1. Open Visual Studio Code.
  2. Click on the Extensions icon in the Activity Bar (usually on the left sidebar).
  3. Search for each extension by name in the search bar.
  4. Click Install for each extension.
  5. For VS Code Icons (if installed):
    • Open the Command Palette (Cmd+Shift+P or Ctrl+Shift+P).
    • Type Icons: Activate VS Code Icons and press Enter.

Configuring Prettier for Format on Save:

  1. Open VS Code Settings (Cmd+, or Ctrl+,).
  2. Search for format on save.
  3. Ensure the Format On Save checkbox is checked. This setting will automatically format your code every time you save a file, using the Prettier extension.

Visual Studio Code (VS Code) A popular source code editor developed by Microsoft for Windows, Linux, and macOS. It features support for debugging, embedded Git control, syntax highlighting, intelligent code completion, snippets, and code refactoring.

Prettier An opinionated code formatter that supports multiple languages including JavaScript, TypeScript, and CSS. It enforces a consistent code style across a project, improving readability and collaboration.

4. Initializing the Expo Project

Once your development environment is set up, you can initialize the Expo project structure.

  1. Create a New Project Folder:

    • Right-click on your desktop or preferred location and create a new folder. Name it meditation or a similar descriptive name.
    • Drag and drop this folder into Visual Studio Code to open it.
  2. Open Integrated Terminal in VS Code:

    • In VS Code, open the integrated terminal (Ctrl+** or **Cmd+).
  3. Run Expo CLI Command:

    • Refer to the latest Expo documentation (docs.expo.dev) for the most up-to-date installation commands. At the time of this tutorial, the command was:
      npx create-expo-app simple-meditation
      This command uses npx (Node Package eXecute) to run the create-expo-app tool, which generates a boilerplate Expo React Native project named simple-meditation.

Expo CLI (Command Line Interface) A command-line tool for working with Expo projects. It allows you to create, build, run, and deploy Expo applications. npx create-expo-app is a command within the Expo CLI to generate a new Expo project with a basic project structure.

Boilerplate A set of basic, reusable code and files that serve as a starting point for a new project. It saves developers from writing the same initial setup code repeatedly.

  1. Navigate to Project Directory:

    • Once the project is created and dependencies are installed, change your current directory in the terminal to the newly created project folder:
      cd simple-meditation
  2. Start the Expo Development Server:

    • Run the command to start the Expo development server:

      npx expo start --clear

      The --clear flag clears the cache, which can resolve some issues during development.

    • This command will start the Expo development server and display a QR code in your terminal.

  3. Run the App on Simulator/Emulator or Physical Device:

    • iOS Simulator: Press i in the terminal. This will open the iOS simulator and run your application. (Requires Xcode to be installed and configured).
    • Android Emulator: Press a in the terminal. This will open the Android emulator and run your application. (Requires Android Studio to be installed and configured).
    • Physical Device (using Expo Go):
      • Open the Expo Go app on your mobile device.
      • Scan the QR code displayed in your terminal using the Expo Go app. Your application will run on your physical device.
      • Web Browser: Press w in the terminal to run the app in your web browser.

Simulator/Emulator Software that imitates the hardware and software of a mobile device (like iOS or Android) on your computer. Simulators and emulators are used for testing mobile applications during development without needing a physical device.

QR Code (Quick Response Code) A type of two-dimensional barcode that can be scanned by smartphones or QR code readers. In Expo, a QR code is used to quickly launch an application on a mobile device via the Expo Go app.

  1. Troubleshooting Errors:
    • If you encounter errors during this process, copy the error message and search online resources like Google, Stack Overflow, or ChatGPT. These platforms often contain solutions and discussions for common development errors.

5. Project Structure and Initial Setup

After successfully initializing the Expo project, it’s essential to understand the basic project structure and perform initial setup steps.

5.1. Project Directory Structure

The create-expo-app command generates a pre-defined project structure:

  • app/ directory: This directory contains the source code for your application. Using Expo Router, it employs file-based routing.
    • index.tsx (or index.jsx): This is the entry point for your application’s home screen.
    • _layout.tsx (or _layout.jsx): Layout files define shared UI components and navigation structure for directories.
    • tabs/ directory: (Created later) Used for implementing tab navigation, grouping related screens.
    • modal/ directory: (Created later) Used for modal screens or components.
  • assets/ directory: Contains static assets like images, fonts, and icons.
  • components/ directory: (Created later) Will house reusable React Native components.
  • constants/ directory: (Created later) Used for storing constant values, data, and configuration files.
  • hooks/ directory: (Optional, for custom React Hooks).
  • scripts/ directory: (Optional, for build or utility scripts).
  • app.json: Configuration file for your Expo app (name, icons, splash screen, etc.).
  • babel.config.js: Babel configuration file for JavaScript transpilation.
  • package.json: Lists project dependencies, scripts, and other project metadata.
  • tailwind.config.js: (Created after installing NativeWind) Configuration file for Tailwind CSS using NativeWind.

File-Based Routing A routing system where the structure of URLs is determined by the file system structure of the application’s source code. Expo Router uses this approach, making navigation intuitive by mapping file paths to routes.

JSX (JavaScript XML) A syntax extension to JavaScript that allows you to write HTML-like structures within JavaScript code. It’s commonly used in React to define UI components.

TSX (TypeScript XML) The TypeScript equivalent of JSX. It combines JSX syntax with TypeScript’s static typing, offering type safety and improved code maintainability for React components.

5.2. Clearing Boilerplate Code and Initial Setup

  1. Clean Up app/index.tsx (or index.jsx):
    • Open app/index.tsx (or index.jsx).

    • Remove all existing boilerplate code within the file.

    • Start with a basic functional component structure:

      import React from 'react';
      import { View, Text, StyleSheet } from 'react-native';
      
      export default function App() {
        return (
          <View style={styles.container}>
            <Text>Hello World</Text>
          </View>
        );
      }
      
      const styles = StyleSheet.create({
        container: {
          flex: 1,
          justifyContent: 'center',
          alignItems: 'center',
        },
      });
    • Hot Reloading: Save the file (Cmd+S or Ctrl+S). Expo’s hot reloading feature will automatically update the app in the simulator/emulator or on your device to reflect your changes without requiring a full refresh. You should see “Hello World” displayed.

Hot Reloading A development feature that automatically updates the application in real-time whenever code changes are saved. It allows developers to see the effects of their code modifications instantly without manually refreshing the app.

  1. Delete Unnecessary Boilerplate Files:

    • In the app/ directory, delete the _layout.tsx and tabs/ directories and their contents. These will be recreated and customized later in the tutorial.
    • Delete any test files (.test.js or .test.tsx) if present, to start with a clean project structure.
  2. Add Asset Files:

    • Copy the downloaded asset folders (images, fonts, audio, logo) into the assets/ directory of your project, replacing the existing assets directory if prompted.
  3. Create Constant Files:

    • Create a new directory named constants/ in the root of your project.
    • Inside constants/, create the following TypeScript files:
      • affirmation-images.typescript
      • meditation-images.typescript
      • meditation-data.typescript
      • colors.typescript
      • affirmations-gallery.typescript
    • Copy the code snippets for each of these files from the GitHub repository’s snippets section and paste them into the respective files. These files define data structures for images, meditation data, affirmation categories, and color palettes used in the app.
  4. Install NativeWind:

    • Open the integrated terminal in VS Code.
    • Run the command to install NativeWind, which allows using Tailwind CSS classes in React Native:
      npm install nativewind
  5. Install Tailwind CSS as a Dev Dependency:

    • Run the command to install Tailwind CSS as a development dependency:
      npm install -D tailwindcss
  6. Initialize Tailwind CSS Configuration:

    • Run the command to initialize the Tailwind CSS configuration file:
      npx tailwindcss init
      This creates a tailwind.config.js file in your project root.
  7. Update tailwind.config.js:

    • Open tailwind.config.js.
    • Replace the default content with the code snippet provided in the GitHub repository’s snippets section for tailwind.config.js. This configuration specifies content sources, NativeWind usage, and custom font families.
  8. Update babel.config.js:

    • Open babel.config.js.

    • In the plugins array, add 'nativewind/babel' as a plugin:

      module.exports = function(api) {
        api.cache(true);
        return {
          presets: ['babel-preset-expo'],
          plugins: ['nativewind/babel'], // Add this line
        };
      };
  9. Run Expo Start Again:

    • Restart the Expo development server to apply the NativeWind and Tailwind CSS configurations: npx expo start --clear.
  10. Apply NativeWind Styles (Example in index.tsx):

    • Open app/index.tsx.

    • Replace the StyleSheet based styles with NativeWind class names. For example, modify the View component style like this:

      <View className="flex-1 justify-center items-center">
        <Text>Hello World</Text>
      </View>

      Here, className is used to apply Tailwind CSS utility classes directly to the React Native component.

  11. Create Declaration File for NativeWind (Optional - to remove VS Code warnings):

    • Create a new file in the root of your project named global.d.ts.

    • Add the following declaration to this file:

      import 'nativewind/types';

      This declaration file helps VS Code recognize and properly handle the className prop for NativeWind, removing potential squiggly line warnings in the editor.

This comprehensive setup process lays the foundation for building the meditation app, equipping you with the necessary tools, project structure, and styling capabilities to proceed with development. The following sections will guide you through building the app’s UI and functionality step-by-step.