ClickCease
Stories in a React Native app

Fast-Guide to Implement Stories in your React Native App

Italo Orihuela
Italo Orihuela
Engineer
Android
iOS
Web
Apr 4, 2024

Currently, Stories have become a staple feature for mobile social networks, providing a dynamic and engaging way for users to share and consume content. React Native developers looking to incorporate this popular feature into their applications can leverage the power of the Amity Social Cloud SDK. This comprehensive guide will walk you through the process of implementing stories in your React Native application using TypeScript and the Amity Social Cloud SDK.

Pre-requisites

Before we begin, ensure you have the following requirements:

  1. Basic knowledge of TypeScript and React Native.
  2. A React Native project set up and ready to go.
  3. The Amity Social Cloud SDK installed in your project.
  4. An Amity Social Cloud Portal account.
  5. An Amity Social Cloud Console Account.

Note: If you haven’t already registered for an Amity account, we recommend following our comprehensive step-by-step guide in the Amity Portal to create your new network.

Step 1: Understanding the Story Creation Process

The Amity Social Cloud SDK provides developers with a suite of functions to create stories. These stories can be of two types: Image and Video. An Image story allows the use of an image file of up to 1GB, while a Video story accommodates video files up to 2GB with a maximum duration of 90 seconds.

Each story creation offers optional StoryItems. The first supported item type, HyperLink, enables the inclusion of a URL and an alias, augmenting the story with additional content for user interaction.

Step 2: Setting Up the Story Repository

To initiate story creation, the first step involves selecting the target type. Currently, the supported targetType is ‘community,’ necessitating the specification of a communityId for story creation within a specific community.

Step 3: Creating an Image Story

The SDK provides the ‘createImageStory()’ function, allowing users to create a story with an image on the specified target. This function requires three parameters: targetType, targetId, and imageFile.

Here’s a TypeScript example of how to use this function:

Step 4: Creating a Video Story

The SDK also provides the ‘createVideoStory()’ function, allowing users to create a story with a video on the specified target. This function requires three parameters: targetType, targetId, and videoFile.

Here’s a TypeScript example of how to use this function:

Step 5: Handling Errors

The Amity SDK utilizes optimistic story creation behavior, resulting in three possible sync states: ‘SYNCING,’ ‘SYNCED,’ and ‘FAILED.’ It’s crucial to handle these states correctly to ensure a smooth user experience.

Final Thoughts

Implementing stories in your React Native application using TypeScript and the Amity Social Cloud SDK can significantly enhance your app’s user experience. While the process may seem complex at first, the Amity Social Cloud SDK simplifies it, enabling you to add this feature quickly and efficiently. Remember, the key to successful implementation is understanding the SDK’s functions and handling errors effectively. With the Amity Social Cloud SDK, you’re not just coding, you’re creating experiences. Feel free to give it a try!