Ignite React Native Boilerplate

repository·master·Indexed 12 days ago

https://github.com/infinitered/ignite

A battle-tested React Native and Expo boilerplate by Infinite Red designed to accelerate mobile app development. It provides a pre-configured tech stack including React Navigation, TypeScript, MMKV for persistence, RN Reanimated, apisauce, and Jest. The project is managed via the ignite-cli (v11.5.0) for project creation and diagnostic reporting, and supports end-to-end testing with Maestro.

Tokens
45.5K
Snippets
172
Records
246
Agent score
95%

What's inside Ignite

  1. Understand the structure of the `app` folder

    master

    The app folder is the primary location for your application logic. Most of your development will occur within this directory. It follows a modular structure where code is organized by concern:

    • app.tsx: The main entry point for the application.
    • components/: Reusable UI components.
    • config/: Application-wide configuration files.
    • devtools/: Setup for development tools like Reactotron.
    • i18n/: Internationalization and localization settings.
    • context/: React Context providers for state management.
    • navigators/: React Navigation configuration and navigators.
    • screens/: The main view components (screens) of your application.
    • services/: Business logic and external integrations, such as API clients.
    • theme/: Styling, colors, and theming definitions.
    • utils/: Helper functions and custom React hooks.
  2. Understand the Ignite Boilerplate tech stack

    master

    An Ignite project comes pre-configured with a battle-tested stack. The default options include:

    • React Native
    • React Navigation (for routing)
    • TypeScript (for type safety)
    • React Native MMKV (integrated with React context for state restoration)
    • apisauce (for REST API communication)
    • Reactotron-ready (for debugging)
    • Expo support (works with Expo and Expo web out of the box)
    • Prebuilt Components (a dozen customizable UI components)
  3. Use Ignite built-in components

    master
    Ignite provides a lightweight, highly customizable design system of built-in React Native components. These are designed for flexibility when building custom mobile designs, rather than providing rigid out-of-the-box styling. While you can use third-party libraries like UI Kitten or RN Elements, Ignite's built-in components are optimized for projects requiring a unique, custom look and feel.
  4. Theming Ignite Apps

    master

    Theming in Ignite provides a consistent look and feel by centralizing style attributes. Theming is managed through several building blocks located in the app/theme directory:

    • Colors & Palettes: Defined in app/theme/colors.ts (and colorsDark.ts for dark mode). Ignite uses a palette-based approach where a set of base colors is defined, which are then mapped to semantic color names. This allows for easy palette swaps while maintaining semantic consistency.
    • Fonts & Typography: Defined in app/theme/fonts.ts. Similar to colors, base fonts are defined and then mapped to semantic font names.
    • Timings: Defined in app/theme/timing.ts for consistent animation durations.
    • Spacing: Managed via a spacing scale in app/theme/spacing.ts. It is highly recommended to use this scale for all layout spacing to ensure consistency.

    For individual component styling (rather than global theme attributes), refer to the Styling documentation.

  5. Navigation in Ignite

    master

    Ignite uses React Navigation v7 for its routing system. All navigators are located in the ./app/navigators directory, with AppNavigator.tsx serving as the primary entry point for the application's navigation tree.

    Key files in the navigation layer:

    • ./app/navigators/AppNavigator.tsx: The root navigator.
    • ./app/navigators/navigationUtilities.tsx: Provides helper functions like getActiveRouteName, useBackButtonHandler, and useNavigationPersistence.

    You can use the Ignite CLI generator to create new navigators automatically.

  6. Configure Navigation in Ignite

    master

    Ignite uses React Navigation v7.

    • Navigators: Located in ./app/navigators. The primary entry point is AppNavigator.tsx.
    • Utilities: The navigationUtilities.ts file provides helper functions such as getActiveRouteName, useBackButtonHandler, and useNavigationPersistence.
  7. How Error Boundaries work in Ignite

    master

    An ErrorBoundary is a React Class Component used to catch JavaScript errors anywhere in their child component tree, unmounting the whole tree instead of the error breaking the entire app.

    In Ignite, you use ErrorBoundary to:

    1. Render Fallback UI: Instead of a blank screen or a crash, you can show a user-friendly ErrorMessage component.
    2. Report Errors: Use the componentDidCatch lifecycle method to send error details to monitoring services (like BugSnag, Sentry, or Honeybadger).

    Ignite provides built-in utilities for crash reporting in app/utils/crashReporting.ts to help integrate these services.

    class ErrorBoundary extends Component<Props, State> {
      state = { error: null, errorInfo: null }
    
      componentDidCatch(error: Error, errorInfo: ErrorInfo) {
        this.setState({
          error,
          errorInfo,
        })
      }
    
      render() {
        return this.state.error ? <ErrorMessage /> : this.props.children
      }
    }
  8. Understand the role of index.tsx

    master

    In an Ignite-generated project, index.tsx serves as the entry point for Expo and React Native. It is intentionally kept minimal to ensure stability. Its primary responsibilities are:

    1. Registering the root component: It uses AppRegistry to tell the native platform which component to mount first.
    2. Environment Setup: It performs the necessary configurations to ensure the environment is correctly prepared for the native build process.
  9. Understand the Ignite folder structure

    master

    Ignite is an opinionated React Native boilerplate. Most of your application logic resides within the ./app directory, while the root directory contains native project files, configuration, and testing infrastructure.

    Project Layout Overview

    your-project
    ├── .maestro          # Maestro e2e tests
    ├── android          # Native Android project files
    ├── app              # Main application source code
    │   ├── components   # Reusable UI building blocks
    │   ├── config       # Environment-specific configurations
    │   ├── context      # React Context providers
    │   ├── devtools     # Devtools setup (e.g., Reactotron)
    │   ├── i18n         # Internationalization/translations
    │   ├── navigators  # React Navigation configurations
    │   ├── screens      # Full-screen React components
    │   ├── services     # External interfaces (APIs, Push Notifications)
    │   ├── theme       # Spacing, colors, and typography
    │   ├── utils        # Shared helpers and utilities
    │   └── app.tsx     # Main application entry point
    ├── assets           # Icons and images
    ├── ignite           # Ignite generator templates
    ├── ios              # Native iOS project files
    ├── test             # Jest configurations and mocks
    ├── app.config.ts   # Dynamic Expo configuration
    ├── app.json         # Static Expo configuration
    ├── eas.json         # Expo EAS build configurations
    └── index.tsx        # App entry point
    your-project
    ├── .maestro
    ├── android
    ├── app
    │   ├── components
    │   ├── config
    │   ├── devtools
    │   ├── i18n
    │   ├── context
    │   ├── navigators
    │   ├── screens
    │   ├── services
    │   ├── theme
    │   ├── utils
    │   └── app.tsx
    ├── assets
    ├── ignite
    │   └── templates
    ├── ios
    ├── test
    │   ├── i18n.test.ts
    │   ├── mockFile.ts
    │   ├── setup.ts
    │   └── test-tsconfig.json
    ├── app.config.ts
    ├── app.json
    ├── eas.json
    ├── index.tsx
    └── package.json
  10. Implement Sidebar (Drawer) Navigation

    master

    Ignite implements sidebar navigation using the DrawerLayout from react-native-gesture-handler.

    To customize the sidebar content (e.g., adding a user avatar, logo, or logout buttons), use the renderNavigationView prop. This prop defines the view rendered inside the drawer that can be toggled open/closed.

    DrawerLayout also supports customization of:

    • Open/close speed
    • Overlay position
    • Transition events and styles