Overview
MessageComposer is a Component that enables users to write and send a variety of messages, including text, image, video, and custom messages. Features such as Live Reaction, Attachments, and Message Editing are also supported by it.
Usage
Integration
The following code snippet illustrates how you can directly incorporate the MessageComposer component into yourlayout.xml
file.
The MessageComposer is responsible for managing runtime permissions. To ensure the ActivityResultLauncher is properly initialized, its object should be created in the the onCreate state of an activity. To ensure that the composer is loaded within the fragment, it is important to make sure that the fragment is loaded in the
onCreate
state of the activity.Actions
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.setOnSendButtonClick
TheOnSendButtonClick
event gets activated when the send message button is clicked. It has a predefined function of sending messages entered in the composer EditText
. However, you can overide this action with the following code snippet.
setOnError
This action doesn’t change the behavior of the component but rather listens for any errors that occur in the MessageList component.YourActivity.java
setOnTextChangedListener
Function triggered whenever the message input’s text value changes, enabling dynamic text handling.YourActivity.java
Filters
MessageComposer component does not have any available filters.Events
Events are emitted by aComponent
. 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 MessageComposer Component does not emit any events of its own.
Customization
To fit your app’s design requirements, you can customize the appearance of the MessageComposer component. We provide exposed methods that allow you to modify the experience and behavior according to your specific needs.Style
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.
Functionality
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 snippetsProperty | Description | Code |
---|---|---|
User | Used to pass user object of which header specific details will be shown | .setUser(user) |
Group | Used to pass group object of which header specific details will be shown | .setGroup(Group) |
disableTypingEvents | Used to disable/enable typing events , default false | .disableTypingEvents(boolean) |
disableSoundForMessages | Used to toggle sound for outgoing messages | .disableSoundForMessages(boolean) |
setInitialComposerText | Used to set predefined text | .setInitialComposerText("Your_Text") |
setMaxLine | Maximum lines allowed to increase in the input field | .setMaxLine(int) |
setAuxiliaryButtonAlignment | controls position auxiliary button view , can be left or right . default right | .setAuxiliaryButtonAlignment(AuxiliaryButtonsAlignment) |
setDisableMentions | 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. | .setDisableMentions(true); |
setCustomSoundForMessages | Used to give custom sounds to outgoing messages | .setCustomSoundForMessages(String) |
setAttachmentButtonVisibility | Hides the attachment button in the composer | .setAttachmentButtonVisibility(View.VISIBLE) |
setStickersButtonVisibility | Hides the stickers button in the composer | .setStickersButtonVisibility(View.GONE) |
setSendButtonVisibility | Hides the send button in the composer | .setSendButtonVisibility(View.VISIBLE) |
setCameraAttachmentOptionVisibility | Controls whether camera attachments are allowed | .setCameraAttachmentOptionVisibility(View.VISIBLE) |
setImageAttachmentOptionVisibility | Controls whether image attachments are allowed | .setImageAttachmentOptionVisibility(View.VISIBLE) |
setVideoAttachmentOptionVisibility | Controls whether video attachments are allowed | .setVideoAttachmentOptionVisibility(View.VISIBLE) |
setAudioAttachmentOptionVisibility | Controls whether audio attachments are allowed | .setAudioAttachmentOptionVisibility(View.VISIBLE) |
setFileAttachmentOptionVisibility | Controls whether file attachments are allowed | .setFileAttachmentOptionVisibility(View.VISIBLE) |
setPollAttachmentOptionVisibility | Controls whether polls can be shared | .setPollAttachmentOptionVisibility(View.VISIBLE) |
setCollaborativeDocumentOptionVisibility | Controls whether collaborative documents can be shared | .setCollaborativeDocumentOptionVisibility(View.VISIBLE) |
setCollaborativeWhiteboardOptionVisibility | Controls whether collaborative whiteboards can be shared | .setCollaborativeWhiteboardOptionVisibility(View.VISIBLE) |
Advanced
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.setTextFormatters
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 Example
themes.xml
setAttachmentOptions
By usingsetAttachmentOptions()
, you can set a list of custom MessageComposerActions
for the MessageComposer Component. This will override the existing list of MessageComposerActions
.

setAuxiliaryButtonView
You can insert a custom view into the MessageComposer component to add additional functionality using the following method.
.setAuxiliaryButtonView()
function.
setSendButtonView
You can set a custom view in place of the already existing send button view. Using the following method.
drawable/custom_send_button.xml
HeaderView
You can set custom headerView to the MessageComposer component using the following method
.setHeaderView()
method.
custom_header_layout