Overview
CometChatCompactMessageComposer is a Component that provides a compact, single-line message input designed for chat applications. It offers a streamlined interface with optional rich text formatting capabilities, supporting bold, italic, strikethrough, code, links, lists, and blockquotes. Features such as Rich Text Formatting, Attachments, Message Editing, Mentions, Stickers, and Voice Recording are supported.
Usage
Integration
The following code snippet illustrates how you can directly incorporate the CompactMessageComposer component into yourlayout.xml file.
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.setOnSendClickListener
ThesetOnSendClickListener event gets activated when the send message button is clicked. It has a predefined function of sending messages entered in the composer. However, you can override this action with the following code snippet.
- Java
- Kotlin
setOnErrorListener
This action doesn’t change the behavior of the component but rather listens for any errors that occur in the CompactMessageComposer component.- Java
- Kotlin
setOnTextChangeListener
Function triggered whenever the message input’s text value changes, enabling dynamic text handling.- Java
- Kotlin
setOnAttachmentClickListener
This action is triggered when the attachment button is clicked. You can override the default attachment sheet behavior with a custom implementation.- Java
- Kotlin
Filters
CompactMessageComposer 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 CompactMessageComposer Component does not emit any events of its own.
Customization
To fit your app’s design requirements, you can customize the appearance of the CompactMessageComposer 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.- Java
- Kotlin
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 snippets| Property | 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) |
| setParentMessageId | Sets the parent message ID for threaded replies | .setParentMessageId(long) |
| setPlaceholderText | Sets the placeholder text for the input field | .setPlaceholderText("Type a message...") |
| setMaxLines | Maximum lines allowed to increase in the input field | .setMaxLines(int) |
| setEnterKeyBehavior | Determines the behavior of the Enter key. SEND_MESSAGE sends the message, NEW_LINE inserts a new line | .setEnterKeyBehavior(EnterKeyBehavior.SEND_MESSAGE) |
| setText | Used to set text programmatically | .setText("Your_Text") |
| setEnableRichTextFormatting | Master switch to enable or disable rich text formatting (bold, italic, etc.) | .setEnableRichTextFormatting(boolean) |
| setRichTextFormattingOptionsVisibility | Controls the visibility of the rich text formatting toolbar | .setRichTextFormattingOptionsVisibility(View.VISIBLE) |
| setShowTextSelectionMenuItems | Shows formatting options (Bold, Italic, Strikethrough, Code) in the text selection context menu | .setShowTextSelectionMenuItems(true) |
| setDisableTypingEvents | Used to disable/enable typing events, default false | .setDisableTypingEvents(boolean) |
| setDisableSoundForMessages | Used to toggle sound for outgoing messages | .setDisableSoundForMessages(boolean) |
| setCustomSoundForMessages | Used to give custom sounds to outgoing messages | .setCustomSoundForMessages(R.raw.sound) |
| 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) |
| setDisableMentionAll | Controls whether group mentions like @all appear in suggestions | .setDisableMentionAll(true) |
| setAttachmentButtonVisibility | Hides the attachment button in the composer | .setAttachmentButtonVisibility(View.VISIBLE) |
| setVoiceRecordingButtonVisibility | Hides the voice recording button in the composer | .setVoiceRecordingButtonVisibility(View.GONE) |
| setStickerButtonVisibility | Hides the sticker button in the composer | .setStickerButtonVisibility(View.GONE) |
| setAIButtonVisibility | Hides the AI button in the composer | .setAIButtonVisibility(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) |
Rich Text Formatting
The CompactMessageComposer includes a built-in rich text editor. However, rich text formatting is disabled by default. Both the formatting toolbar and markdown syntax parsing (e.g., typing**bold**) are inactive until explicitly enabled.
To fully leverage rich text formatting, you need to enable the following properties:
setEnableRichTextFormatting(true)— Master switch that activates formatting. Without this, even manually typed markdown syntax like**text**will be sent as plain text.setRichTextFormattingOptionsVisibility(View.VISIBLE)— Shows the formatting toolbar above the input field.setShowTextSelectionMenuItems(true)— Adds formatting options (Bold, Italic, Strikethrough, Code) to the text selection context menu.
Supported Format Types
| Format | Description | Markdown Syntax |
|---|---|---|
| Bold | Makes text bold | **text** |
| Italic | Makes text italic | *text* |
| Strikethrough | Strikes through text | ~~text~~ |
| Inline Code | Formats as inline code | `code` |
| Code Block | Creates a code block | ```code``` |
| Blockquote | Creates a blockquote | > text |
| Numbered List | Creates a numbered list | 1. item |
| Bullet List | Creates a bullet list | - item |
| Link | Creates a hyperlink | [text](url) |
Configuration
- Java
- Kotlin
enableRichTextFormatting | richTextFormattingOptionsVisibility | Result |
|---|---|---|
false | - | Plain text, no formatting |
true | View.GONE | No toolbar, only text selection menu items work |
true | View.VISIBLE | Toolbar visible above input, text selection menu items also enabled |
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 Examplethemes.xml
- Java
- Kotlin
setAttachmentOptions
By usingsetAttachmentOptions(), you can set a list of custom MessageComposerActions for the CompactMessageComposer Component. This will override the existing list of MessageComposerActions.
- Java
- Kotlin
- Java
- Kotlin
setAuxiliaryButtonView
You can insert a custom view into the CompactMessageComposer component to add additional functionality using the following method.- Java
- Kotlin
.setAuxiliaryButtonView() function.
- Java
- Kotlin
setSendButtonView
You can set a custom view in place of the already existing send button view using the following method.- Java
- Kotlin
drawable/custom_send_button.xml
- Java
- Kotlin
setHeaderView
You can set custom headerView to the CompactMessageComposer component using the following method.- Java
- Kotlin
.setHeaderView() method.
custom_header_layout.xml
- Java
- Kotlin
setFooterView
You can set a custom footer view to the CompactMessageComposer component using the following method.- Java
- Kotlin