React Native, introduced by Facebook (now Meta) in 2015, revolutionized mobile development by allowing developers to build native-performing iOS and Android apps from a single JavaScript codebase. It renders using actual native UI components, creating apps indistinguishable from those built with Swift or Kotlin.
Key Benefits:
Reduced development time and cost.
Significant code sharing between platforms.
Faster iteration with Hot Reloading.
Access to native device features.
Easier transition for web developers into mobile development.
The New Architecture
React Native’s New Architecture significantly improves performance and capabilities by replacing the old asynchronous bridge. It consists of several key components:
JavaScript Interface (JSI)
A C++ layer enabling direct, synchronous communication between JavaScript and native code, eliminating the need for JSON serialization used by the old bridge.
Benefits: Faster performance, lower memory usage, quicker startup, enables modern React features like Suspense.
Turbo Modules
The evolution of Native Modules. They load lazily (only when needed) and use JSI for direct, efficient communication with native platform APIs.
Benefits: Lazy loading, direct JSI communication (faster), supports sync/async calls, type-safe (via CodeGen), better memory management.
Fabric
The new rendering system. It uses JSI for direct UI manipulation and enables multi-threaded rendering for a smoother user experience.
Benefits: Multi-threaded rendering, synchronous layout potential, direct native UI access via JSI, improved state management with persistent C++ UI trees.
Expo is an open-source framework and platform built on top of React Native. It provides a managed workflow with pre-built tools and services, abstracting away much of the native configuration complexity.
Core Features:
Expo CLI: Development command-line tool.
Expo Go: A client app to instantly run projects on physical devices without native builds.
Expo SDK: A curated set of native APIs and components (location, camera, etc.).
EAS (Expo Application Services): Cloud build, submission, and update services.
What: A pre-built app from the App/Play Store containing the Expo SDK.
Pros:
Fastest way to start and test.
No native build tools needed initially.
Instantly run code on a physical device.
Cons:
Limited to native modules included in the Expo SDK version.
Cannot add custom native code or libraries not in Expo Go.
Limited native configuration (app icon, splash screen require a build).
Use When: Starting new projects, prototyping, learning, apps using only Expo SDK APIs.
What: A custom build of your own app that includes expo-dev-client.
Pros:
Full access to any native module (Expo SDK or third-party).
Allows custom native code modifications.
Full control over native configuration (app icon, etc.).
Retains Expo workflow benefits (Fast Refresh, Dev Menu).
Cons:
Requires an initial native build (local or via EAS Build).
Slightly longer setup than Expo Go.
Use When: Needing custom native modules, modifying native config, preparing for production.
Creating a Development Build (using EAS):
Terminal window
# Install EAS CLI (if needed)
npminstall-geas-cli
# Log in
easlogin
# Configure project (if needed)
easbuild:configure
# Build for platform
easbuild--profiledevelopment--platformandroid# or ios
Run with: npx expo start --dev-client
React vs. React Native Syntax
While built on React, React Native uses native components instead of web elements (HTML DOM).
React Native uses JavaScript objects for styling, similar to inline styles in web, but commonly uses StyleSheet.create for organization and performance. It primarily uses Flexbox for layout (applied by default to <View>).
// React Native Styling
import { StyleSheet, View, Text } from'react-native';
const styles = StyleSheet.create({
container: {
flex: 1, // Take up available space
padding: 20,
backgroundColor: 'white',
},
title: {
fontSize: 24,
fontWeight: 'bold',
color: 'blue',
marginBottom: 10, // Use numbers for pixel values
}
});
<Viewstyle={styles.container}>
<Textstyle={styles.title}>Styled Title</Text>
</View>
Event names differ (onClick vs. onPress). React Native provides touchable components like TouchableOpacity or Pressable.
// React (Web)
<buttononClick={handleClick}>Click</button>
// React Native
import { TouchableOpacity, Text } from'react-native';
<TouchableOpacityonPress={handlePress}>
<Text>Press Me</Text>
</TouchableOpacity>
Web uses libraries like react-router-dom. React Native uses dedicated libraries like react-navigation designed for native stack, tab, and drawer navigation patterns.
Environment Setup
Choose the setup method that best suits your needs.
1. Using Expo (Recommended Start)
The quickest way to get started.
Install Expo CLI (Optional but Recommended):
Terminal window
npminstall-gexpo-cli
Create a New Project:
Terminal window
npxcreate-expo-app@latestYourProjectName
cdYourProjectName
Start the Development Server:
Terminal window
npxexpostart
Scan the QR code with the Expo Go app on your device, or use the commands to open in an emulator/simulator. For custom native code, create a Development Build (see above).
2. Using React Native CLI (Bare Workflow)
Provides full control over the native project files. Requires more setup.
General Steps (Summarized - Refer to Official Docs for Details):
Install Core Dependencies:
Node.js: Use the LTS version.
Watchman: (Recommended for macOS/Linux) File watching service. brew install watchman
Java Development Kit (JDK): Typically OpenJDK 17. Use package managers like brew (macOS) or download directly. Set JAVA_HOME.
Install Android Dependencies:
Android Studio: Install the latest version.
Android SDK: Use Android Studio’s SDK Manager to install the required SDK Platform (e.g., Android 14 - API 34) and Build-Tools. Ensure Command-line Tools are installed.
Emulator/Device: Set up an Android Virtual Device (AVD) via Android Studio or enable USB Debugging on a physical device.
Configure Environment Variables: Set ANDROID_HOME and add platform-tools/emulator to your PATH.
Install iOS Dependencies (macOS Only):
Xcode: Install from the Mac App Store.
Xcode Command Line Tools: Install via Xcode or xcode-select --install.
CocoaPods: Dependency manager for iOS. sudo gem install cocoapods