MessageList is a Composite Component that displays a list of messages and effectively manages real-time operations. It includes various types of messages such as Text Messages, Media Messages, Stickers, and more.MessageList is primarily a list of the base component MessageBubble. The MessageBubble Component is utilized to create different types of chat bubbles depending on the message type.
Actions dictate how a component functions. They are divided into two types: Predefined and User-defined. You can override either type, allowing you to tailor the behavior of the component to fit your specific needs.
1. onThreadRepliesPress
onThreadRepliesPress is triggered when you click on the threaded message bubble. The onThreadRepliesPress action doesn’t have a predefined behavior. You can override this action using the following code snippet.
You can adjust the MessagesRequestBuilder in the MessageList Component to customize your message list. Numerous options are available to alter the builder to meet your specific needs. For additional details on MessagesRequestBuilder, please visit MessagesRequestBuilder.In the example below, we are applying a filter to the messages based on a search substring and for a specific user. This means that only messages that contain the search term and are associated with the specified user will be displayed
Events are emitted by a Component. By using event you can extend existing functionality. Being global events, they can be applied in Multiple Locations and are capable of being Added or Removed.The list of events emitted by the Message List component is as follows.
Event
Description
openChat
this event alerts the listeners if the logged-in user has opened a user or a group chat
ccMessageEdited
Triggers whenever a loggedIn user edits any message from the list of messages. It will have two states such as: inProgress & sent
ccMessageDeleted
Triggers whenever a loggedIn user deletes any message from the list of messages
ccActiveChatChanged
This event is triggered when the user navigates to a particular chat window.
ccMessageRead
Triggers whenever a loggedIn user reads any message.
ccMessageDelivered
Triggers whenever messages are marked as delivered for the loggedIn user
To fit your app’s design requirements, you can customize the appearance of the conversation component. We provide exposed methods that allow you to modify the experience and behavior according to your specific needs.
Using Style you can customize the look and feel of the component in your app, These parameters typically control elements such as the color, size, shape, and fonts used within the component.
1. MessageList Style
You can set the MessageListStyle to the MessageList Component Component to customize the styling.
Sets sender/receiver name text color on a message bubble.
nameTextFont
FontStyleInterface
Sets sender/receiver name text font on a message bubble
emptyStateTextColor
string
Sets the empty text colour for message list
emptyStateTextFont
FontStyleInterface
Sets the empty text font for message list
errorStateTextColor
string
Sets the error text colour for message list
errorStateTextFont
FontStyleInterface
Sets the error text font for message list
timestampTextFont
FontStyleInterface
Sets the timestamp text font for message list
timestampTextColor
string
Sets the timestamp text colour for message list
threadReplyTextColor
string
Sets the thread reply text colour for message list
threadReplyTextFont
FontStyleInterface
Sets the thread reply text font for message list
threadReplySeparatorColor
string
Sets the thread reply saperator colour for message list
threadReplyIconTint
string
Sets thread reply icon tint
loadingIconTint
string
Sets the loading icon tint for message list
2. Avatar Style
To apply customized styles to the Avatar component in the Conversations Component, you can use the following code snippet. For further insights on Avatar Styles refer
These are a set of small functional customizations that allow you to fine-tune the overall experience of the component. With these, you can change text, set custom icons, and toggle the visibility of UI elements.
Below is a list of customizations along with corresponding code snippets
Property
Description
Code
user
Used to pass user object of which header specific details will be shown
user={chatUser}
group
Used to pass group object of which header specific details will be shown
group={chatGroup}
alignment
used to set the alignmet of messages in CometChatMessageList. It can be either leftAligned or standard. Type: MessageListAlignmentType
alignment={"standard"}
emptyStateText
used to set text which will be visible when no messages are available
emptyStateText="Your Custom Empty State text"
errorStateText
used to set text which will be visible when error in messages retrieval
errorStateText="Your Custom Error State text"
disableSoundForMessages
used to enable/disable sound for incoming/outgoing messages , default false
disableSoundForMessages={true}
customSoundForMessages
used to set custom sound for outgoing message
customSoundForMessages="your custom sound for messages"
readIcon
used to set custom read icon visible at read receipt. Type: ImageType
readIcon={{uri: <image url>}} OR import customReadIcon from "./customReadIcon.svg"; ``readIcon={customReadIcon}
deliveredIcon
used to set custom delivered icon visible at read receipt. Type: ImageType
deliveredIcon={{uri: <image url>}} OR import customDeliveredIcon from "./customDeliveredIcon.svg"; ``deliveredIcon={customDeliveredIcon}
sentIcon
used to set custom sent icon visible at read receipt. Type: ImageType
sentIcon={{uri: <image url>}} OR import customSentIcon from "./customSentIcon.svg"; ``sentIcon={customSentIcon}
waitIcon
used to set custom wait icon visible at read receipt. Type: ImageType
waitIcon={{uri: <image url>}} OR import customWaitIcon from "./customWaitIcon.svg"; ``waitIcon={customWaitIcon}
showAvatar
used to toggle visibility for avatar
showAvatar={true}
hideActionSheetHeader
used to hides the header of the action sheet
hideActionSheetHeader={true}
timestampAlignment
used to set receipt’s time stamp alignment. It can be either top or bottom. Type: MessageTimeAlignmentType
timestampAlignment={"top"}
newMessageIndicatorText
used to set new message indicator text
newMessageIndicatorText="Custom Indicator text"
scrollToBottomOnNewMessage
should scroll to bottom on new message? , by default false
scrollToBottomOnNewMessages={true}
disableMentions
Sets whether mentions in text should be disabled. Processes the text formatters If there are text formatters available and the disableMentions flag is set to true, it removes any formatters that are instances of CometChatMentionsFormatter.
disableMentions={true}
hideReceipt
Used to control the visibility of read receipts without affecting the functionality of marking messages as read and delivered.
For advanced-level customization, you can set custom views to the component. This lets you tailor each aspect of the component to fit your exact needs and application aesthetics. You can create and define your views, layouts, and UI elements and then incorporate those into the component.
CometChatMessageTemplate is a pre-defined structure for creating message views that can be used as a starting point or blueprint for creating message views often known as message bubbles. For more information, you can refer to CometChatMessageTemplate.You can set message Templates to MessageList by using the following code snippet
The EmptyStateView method provides the ability to set a custom empty state view in your app. An empty state view is displayed when there are no messages for a particular user.
Assigns the list of text formatters. If the provided list is not null, it sets the list. Otherwise, it assigns the default text formatters retrieved from the data source. To configure the existing Mentions look and feel check out CometChatMentionsFormatter
ShortCutFormatter.ts
App.tsx
import { CometChat } from "@cometchat/chat-sdk-react-native";import { CometChatTextFormatter, SuggestionItem,} from "@cometchat/chat-uikit-react-native";export class ShortCutFormatter extends CometChatTextFormatter { constructor() { super(); this.trackCharacter = "!"; } search = (searchKey: string) => { let data: Array<SuggestionItem> = []; CometChat.callExtension("message-shortcuts", "GET", "v1/fetch", undefined) .then((data: any) => { if (data && data?.shortcuts) { let suggestionData = Object.keys(data.shortcuts).map((key) => { return new SuggestionItem({ id: key, name: data.shortcuts[key], promptText: data.shortcuts[key], trackingCharacter: "!", underlyingText: data.shortcuts[key], }); }); this.setSearchData(suggestionData); // setting data in setSearchData(); } }) .catch((error) => { // Some error occured }); this.setSearchData(data); }; // return null in fetchNext, if there's no pagination. fetchNext = () => { return null; };}
import React from "react";import { CometChat } from "@cometchat/chat-sdk-react-native";import { CometChatMessageList } from "@cometchat/chat-uikit-react-native";import { ShortCutFormatter } from "./ShortcutsTextFormatter";function App(): React.JSX.Element { const [chatUser, setChatUser] = React.useState<CometChat.User | undefined>(); React.useEffect(() => { CometChat.getUser("uid").then((user) => { setChatUser(user); }); }, []); const shortcutFormatter = new ShortCutFormatter(); return <CometChatMessageList textFormatters={[new ShortcutFormatter()]} />;}
The MessageInformationConfiguration indeed provides access to all the Action, Filters, Styles, Functionality, and Advanced properties of the MesssageInformation component.Please note that the 🛑 symbol are not accessible within the Configuration Object.Example
iOS
Android
In the above example, we are styling a few properties of the MesssageInformation component using MessageInformationConfiguration.