Key Concepts
React Native, Expo, AppRide, Cross-Platform Development, Native Components (View, Text, TextInput, ScrollView), Expo Router, File-Based Routing, Root Layout, Stack Navigation, Tab Navigation, Vector Icons, Full-Stack Development, Backend as a Service, Authentication (OAuth), Relational Databases, AppRite SDK, Environment Variables, Route Guards, Keyboard Avoiding View, React Native Paper, Stylesheet, Context API, Providers, Hooks, Database Collections, Database Documents, Database Attributes, Permissions, Real-time Subscriptions, Gesture Handling, Swipeable Components, State Management, Asynchronous Functions, Error Handling, UI Styling, Data Fetching, Data Sorting, Data Filtering, Data Mapping, Component Composition.
React Native Crash Course 2025: Building a Habit Tracker App
Introduction
The video introduces a React Native crash course for 2025, aiming to guide beginners through building a full-stack habit tracker app using React Native, Expo, and AppRide. The course covers UI creation, screen management, state management, backend connectivity, and mobile experience development.
React Native Fundamentals
React Native enables cross-platform app development using JavaScript and React. It allows access to native device features and uses a single codebase for iOS and Android.
Core React Native Components:
- View: A container similar to a
divin HTML, used for layout. - Text: Displays text, similar to a
ptag in HTML. - TextInput: Accepts text input from users, tailored for developer experience.
- ScrollView: Creates scrollable areas when content exceeds screen size.
Expo Framework
Expo simplifies React Native development by providing tools, libraries, and services. It allows instant app preview using the Expo Go app, access to device features, and a fast refresh development environment. Expo is suitable for rapid prototyping and cross-platform app building.
Project Setup
The video demonstrates setting up a React Native project using Expo:
- Creating the App: Using the command
npx create-expo-app .to create a new Expo app in the current directory. - Running the App: Using
npm run web,npm run ios, ornpm run androidto run the app on different platforms. - Resetting the Project: Using
npm run reset projectto remove boilerplate code and start with a clean slate.
Expo Router and Navigation
Expo Router facilitates file-based routing. The app directory contains files and folders that define app screens.
- index.tsx: The entry point of the app.
- _layout.tsx (Root Layout): Defines shared UI elements across all routes.
- Creating New Routes: Adding new
.tsxfiles in theappdirectory automatically creates new screens. - Navigation: Using the
Linkcomponent fromexpo-routerto navigate between screens. - Styling: Applying styles using inline styles or the
StyleSheetobject from React Native.
Tab Navigation
Tab navigation is implemented using the tabs folder.
- Creating a Tabs Folder: Creating a folder with parentheses
(tabs)to group screens. - Adding Screens: Moving existing screens into the tabs folder.
- Creating a Layout: Adding a
_layout.tsxfile inside the tabs folder to define the tab navigator. - Using the Tabs Component: Importing the
Tabscomponent fromexpo-routerand usingTabs.Screento define each tab. - Customizing Tabs: Using the
screenOptionsprop to customize tab bar appearance, icons, and colors. - Vector Icons: Using the
expo-vector-iconslibrary to add icons to the tab bar.
Full-Stack Integration with AppRide
The video integrates the React Native app with AppRide for backend services.
- Setting up AppRide: Creating an account on AppRide and creating a new project.
- Installing AppRide SDK: Installing the
react-native-appwriteandreact-native-url-polyfillpackages usingnpx expo install. - Configuring AppRide: Creating an
appwrite.tsfile to configure the AppRide client. - Environment Variables: Using
.envfiles to store API keys and project IDs securely. - Creating a Platform: Adding a React Native platform in AppRide settings.
- Initializing Services: Initializing the
accountanddatabasesservices from AppRide.
Authentication Flow
The video implements an authentication flow using AppRide.
- Creating an Auth Screen: Creating an
auth.tsxfile for the sign-in/sign-up screen. - Keyboard Avoiding View: Using the
KeyboardAvoidingViewcomponent to prevent the keyboard from overlapping the form. - React Native Paper Components: Using
TextInputandButtoncomponents from React Native Paper for styling. - State Management: Using
useStateto manage input values and track whether the user is signing in or signing up. - Auth Context: Creating an
authContext.tsxfile to manage authentication state using React's Context API. - Auth Provider: Creating an
AuthProvidercomponent to wrap the app and provide authentication context. - UseAuth Hook: Creating a
useAuthhook to access authentication functions and user data. - Route Guard: Creating a
RouteGuardcomponent to protect routes based on authentication status. - Sign-up and Sign-in Functions: Implementing
signUpandsignInfunctions using AppRide'saccountservice. - Error Handling: Displaying error messages using the
useThemehook from React Native Paper.
Database Setup
The video sets up a relational database in AppRide.
- Creating a Database: Creating a new database in AppRide called
habitsDB. - Creating Collections: Creating two collections:
habitsandhabitCompletions. - Defining Attributes: Defining attributes for each collection, such as
userId,title,description,streakCount,lastCompleted,createdAtfor thehabitscollection, andhabitId,userId,completedAtfor thehabitCompletionscollection. - Setting Permissions: Configuring permissions for each collection to control user access.
Adding Habits
The video implements the functionality to add new habits.
- Creating Add Habit Screen: Creating an
addHabit.tsxfile for the add habit screen. - UI Components: Using
TextInputandButtoncomponents from React Native Paper. - Segmented Buttons: Using segmented buttons to select the frequency of the habit.
- State Management: Using
useStateto manage input values and the selected frequency. - Handle Submit Function: Implementing a
handleSubmitfunction to create a new habit in thehabitscollection using AppRide'sdatabasesservice. - Error Handling: Displaying error messages using the
useThemehook from React Native Paper.
Displaying Habits
The video implements the functionality to display habits on the today's habits screen.
- Fetching Habits: Creating a
fetchHabitsfunction to retrieve habits from thehabitscollection using AppRide'sdatabasesservice. - State Management: Using
useStateto store the list of habits. - UseEffect Hook: Using the
useEffecthook to fetch habits when the component mounts. - Mapping Habits: Mapping through the list of habits to display each habit in a card.
- UI Components: Using
Surface,Text, andMaterialCommunityIconscomponents to style the habit cards. - Empty State: Displaying a message when there are no habits.
- ScrollView: Using the
ScrollViewcomponent to make the list of habits scrollable.
Real-time Updates
The video implements real-time updates using AppRide's client.subscribe function.
- Subscribing to Events: Subscribing to
create,update, anddeleteevents on thehabitscollection. - Fetching Habits on Event: Fetching the list of habits whenever a new event occurs.
- Cleaning up Subscription: Unsubscribing from the event when the component unmounts to prevent memory leaks.
Gesture Handling and Swipeable Actions
The video implements swipeable actions using the react-native-gesture-handler library.
- Installing Gesture Handler: Installing the
react-native-gesture-handlerpackage usingnpx expo install. - Gesture Handler Root View: Wrapping the app with the
GestureHandlerRootViewcomponent in the_layout.tsxfile. - Swipeable Component: Wrapping each habit card with the
Swipeablecomponent. - Refs: Using
useRefto create a list of refs for each swipeable component. - Render Left Actions and Render Right Actions: Implementing
renderLeftActionsandrenderRightActionsfunctions to render the actions that appear when the user swipes left or right. - OnSwipeableOpen Prop: Using the
onSwipeableOpenprop to detect when the user swipes left or right.
Completing Habits
The video implements the functionality to complete habits.
- Creating Habit Completions Collection: Creating a
habitCompletionscollection to store completed habits. - Handle Complete Habit Function: Implementing a
handleCompleteHabitfunction to create a new document in thehabitCompletionscollection and update thestreakCountandlastCompletedattributes in thehabitscollection. - Preventing Multiple Completions: Preventing the user from completing the same habit multiple times in the same day.
- Fetching Today's Completions: Creating a
fetchTodayCompletionsfunction to retrieve the habits that were completed today. - Subscribing to Completions Events: Subscribing to
createevents on thehabitCompletionscollection. - Styling Completed Habits: Changing the opacity of the habit card to indicate that it has been completed.
Ranking Habits
The video implements the functionality to rank habits based on their streak.
- Get Streak Data Function: Creating a
getStreakDatafunction to calculate the streak, best streak, and total completions for a given habit. - Habit Streaks Array: Creating a
habitStreaksarray by mapping through the list of habits and calling thegetStreakDatafunction for each habit. - Sorting Habits: Sorting the
habitStreaksarray based on the best streak. - Displaying Ranked Habits: Displaying the top three ranked habits in a table.
- Styling Ranked Habits: Styling the ranked habits using CSS.
Conclusion
The video concludes by summarizing the key concepts covered in the crash course and encouraging viewers to explore the code repository for best practices and further learning. It also promotes the instructor's React course and encourages viewers to enroll.
AI summaries can miss context or contain errors. Check important details against the original video.