NewPlatano

Building a Threads Clone with React Native, TypeScript & Expo!

Beto, July 20, 2023 · 39,786 views

Learn how to create a Threads clone UI using React Native with Expo SDK 49 and TypeScript. It focuses on building the interface with dummy data and implementing smooth animations similar to the real Threads app. The project uses the new Expo Router for file-based navigation and supports dark mode out of the box.

If you want to learn how to set up an Expo project with the latest SDK, use Expo Router version 2, and create a modern social feed UI with animations, this video is for you. It’s ideal for React Native developers looking to explore Expo’s latest features and build a polished app UI quickly.

What's inside

  • Starting a new Expo 49 project with TypeScript and Expo Router
  • Managing dependencies and upgrading to Expo SDK 49
  • Understanding Expo Router’s file-based navigation and layout system
  • Setting up stack and tab navigation with Expo Router
  • Using the Link component for navigation and modals
  • Handling missing routes with Expo Router’s error boundary
  • Implementing dark mode support in the UI
  • Adding animations that mimic Threads app transitions

Starting a new Expo 49 project with TypeScript and Expo Router

I start by creating a new Expo project using the command with the Expo Router and TypeScript template. This template comes preconfigured with Expo Router version 2 and TypeScript support, speeding up development. The project is named and opened in Visual Studio Code.

I prefer using Yarn over npm, so I deletes and before running to install dependencies. This setup ensures the project uses Yarn as the package manager.

Managing dependencies and upgrading to Expo SDK 49

Although the template installs Expo SDK 49, I double-check the version in . I run to ensure the latest Expo version is installed. Afterward, I run to update all Expo-related dependencies to versions compatible with SDK 49.

This step is crucial to avoid version mismatches and warnings when running the app. Once dependencies are fixed, the app runs smoothly on the iOS simulator.

Understanding Expo Router’s file-based navigation and layout system

Expo Router uses the file system to manage navigation. Inside the folder, each file or folder represents a route or screen. The root file acts as the main entry point, defining the app’s navigation structure and error boundaries.

I explain that the layout file wraps the app in an error boundary to catch navigation errors gracefully. It also handles loading fonts and shows a splash screen while loading. The root layout defines a stack navigator that contains tabs and modals.

Setting up stack and tab navigation with Expo Router

The tabs navigation is defined inside the folder with its own and . The tabs layout imports from Expo Router and configures the tab bar. This pattern of having a layout and index file per folder is consistent throughout the app.

The root stack navigator includes the tabs stack as the main screen and a modal screen accessible from anywhere. This structure allows presenting modals on top of the tab navigation.

Expo Router’s component enables declarative navigation with autocomplete support. I use to open the modal screen by specifying its route in the prop.

This approach simplifies navigation and keeps it consistent across the app. The modal can be triggered from any screen using the component, making the UI more interactive.

Handling missing routes with Expo Router’s error boundary

If navigation targets a route that does not exist, Expo Router’s error boundary prevents the app from crashing. Instead, it shows a friendly error screen indicating the route is missing and provides a back button.

I demonstrate this by changing the modal route to a non-existent path. This feature improves user experience by handling navigation errors gracefully.

Implementing dark mode support in the UI

The Threads clone UI supports dark mode, matching the real app’s look and feel. I use React Native’s appearance APIs and styling to toggle between light and dark themes.

This ensures the app adapts to the user’s system preferences, providing a polished and modern user interface.

Adding animations that mimic Threads app transitions

I also covers adding smooth animations similar to Threads. I use a third-party animation library integrated with React Native to replicate the app’s reload and transition animations.

These animations are customizable, allowing changes to colors and effects. They enhance the user experience by making the UI feel responsive and lively.

Resources

CourseReact Native course

Let's connect!

Had a win? Get featured on Code with Beto.Share your story