React Native Cross-Platform Chat App with PubNub SDK
Build a seamless React Native chat app with PubNub SDK. Support group chats, presence indicators, and more—cross-platform for iOS & Android
Build a Chat App with PubNub's CORE SDK for React Native
When developing an application with chat, React Native allows you to develop for both Android and iOS from a single code base.
This React Native chat app tutorial will walk you through developing a React Native chat app using the PubNub React and Javascript SDKs with the following features:
Messaging and chat bubbles: Group chat with everyone in the same room
Presence indicators for participants when they join or leave the room
Load historical messages sent or received before you joined the room
Customize your name
Messages are timestamped
Runs on Android and iOS from the same codebase
The source code for this application can be found on Github at https://github.com/PubNubDevelopers/GettingStarted-ReactNative-SDK-Tutorial
This is a Getting Started tutorial and only scratches the surface of what you can achieve with the PubNub SDK. See our other tutorials to add features like whiteboards, 1:1 chat, message reactions, push notifications or location tracking.
Why Build a React Native Chat App?
React Native is a powerful framework for building fast, responsive, and scalable chat apps on both Android and iOS from a single codebase. This multi-platform support streamlines development, reducing time to market and maintenance costs.
Key benefits when building production-ready chat apps with React:
Performance: With near-native performance, React Native provides a smooth experience, handling large volumes of messages with low latency.
Cross-Platform Consistency: Ensure a consistent user experience across Android and iOS without writing separate code for each platform.
Customizable UI: React Native allows full control over UI components, from chat bubbles to real-time typing indicators, offering flexibility for building tailored chat experiences.
Code Reusability: Reuse much of your code from web apps, speeding up development and reducing maintenance efforts.
Scalability: supports apps that scale effortlessly to millions of users, ensuring your chat app grows with your user base.
Security: Enterprise-level security features like encryption and compliance with HIPAA, GDPR, and SOC2 protect sensitive data.
Large Ecosystem: A vibrant community and extensive resources help developers quickly integrate features like message reactions, file sharing, and push notifications.
React Native provides an efficient path to creating high-quality, cross-platform chat apps while optimizing for performance, scalability, and security.
Prerequisites
Before running this application, be sure you have the following installed:
React Native environment setup, including:
A code editor such as Visual Studio Code
Xcode (for the build step)
Android Studio (for the build step)
If you are using Apple silicon, pay particular attention to any text that mentions "M1". If you already have a development environment setup, ensure it aligns with the versions given in the React Native setup guide, especially JDK and Node.JS.
The PubNub SDKs support applications created with the React Native CLI or the Expo CLI however this tutorial will concentrate on the React Native CLI.
Those developers targeting Expo Go can refer to our separate React Native getting started application, but that is outside of the scope of this tutorial.
Download Free Source Application
This tutorial takes a simple but functional chat app written with React Native and shows how it was developed. You are free to follow the React Native chat tutorial however works for you, either browse through the finished code or add the functionality progressively by checking out the tutorial branch. This code is available for free and released under MIT license.
In a terminal, navigate to an empty folder. Enter the following command to clone the repository:
git clone https://github.com/PubNubDevelopers/GettingStarted-ReactNative-SDK-Tutorial.git
And navigate to the application folder:
cd GettingStarted-ReactNative-SDK-Tutorial
cd GettingStarted
Install the applications dependencies
npm install
To check you have everything set up correctly, you should now be able to build the app for both Android and iOS (remember that iOS development will require a mac).
Android:
npm run android
iOS:
cd ios
pod install
cd ../
npm run ios
(optional) The main git branch contains the completed version of this tutorial. If you would like to add the functionality described in this tutorial progressively into the app then please check out the following tutorial branch:
git checkout tutorial_step_0
Create keys
Demo keys
You're ready to go!
We’ve assigned demo keys which are set up to support the features of this tutorial app. These will be active for 72 hours but you can sign up for a free account at the end of the tutorial to create your own permanent keys.
The demo keys have the following functionality activated ready for your application:
Presence
Message Persistence You will be able to see user’s message history and meta data.
Stream Controller You will be able to receive messages against a group of channels, or post one message to multiple channels.
App Context This allows you to manage the metadata of your users and channels.
My own keys
To use your own keys, create a free account and a keyset with Presence, Message Persistence, Stream Controller, and App Context on.
You can create the keyset with the Admin API, PubNub's REST API for account management. An Account Owner or Account Admin creates a Service Integration and its API key in the Admin Portal under Organization Settings → API Management. Give it read & write access to apps and keysets, plus read access to secret keys, which keyset creation requires. With that key, create an app, then create a keyset in it and pass the keyset's configuration in the same request. The response includes the publish and subscribe keys. See the Admin API documentation for the requests and keyset settings.
Build and run
Congratulations - what's next?
Chat SDK Documentation
Chat OverviewJavaScript SDK DocsReact SDK DocsChat Developer PathLive Tour
Start the live coding tourExplore other Sample apps
Simple React Native reference appDeveloping to a tight deadline? Explore Chat Components
Chat Components IntroductionReady to get beyond Proof of Concept?
Schedule a 15 minute chat with one of our experts to get your project moving
Talk to an ExpertTake it to production on your own keys
Create a free PubNub account to get permanent keys for this app.