AI Integration Quick Reference
AI Integration Quick Reference
Where It Fits
CometChatCompactMessageComposer is a Component that provides a compact, streamlined message input with optional rich text formatting capabilities. It supports bold, italic, underline, strikethrough, and code formatting, along with auto-expanding input, attachments, mentions, voice recording, and message editing.
This is a compact variant of CometChatMessageComposer. It shares the same props API but adds rich text formatting controls, auto-expanding input configuration, and additional callbacks.
Wire it alongside CometChatMessageHeader and CometChatMessageList to build a standard chat view.
Minimal Render
Actions and Events
Callback Props
onSendButtonPress
Fires when the send message button is clicked. Overrides the default send behavior.onError
Fires on internal errors (network failure, auth issue, SDK exception).onChangeText
Fires as the user types in the composer input.onMentionLimitReached
Fires when the maximum mention limit per message is reached.Global UI Events
CometChatUIEventHandler emits events subscribable from anywhere in the application. Add listeners and remove them on cleanup.
| Event | Fires when | Payload |
|---|---|---|
ccMessageSent | A message is sent | { message: CometChat.BaseMessage, status: string } |
ccMessageEdited | A message is edited | { message: CometChat.BaseMessage, status: string } |
In React 18 StrictMode,
useEffect runs twice on mount in development. The component handles listener cleanup internally, but any additional listeners added alongside the component need cleanup in the useEffect return function to avoid duplicate event handling.Rich Text Formatting
The CompactMessageComposer includes a built-in rich text editor. Rich text is enabled by default viaenableRichTextEditor={true}.
Formatting Toolbar
The toolbar provides the following formatting tools:| Tool | Description |
|---|---|
| Bold | Bold text |
| Italic | Italic text |
| Underline | Underline text |
| Strikethrough | Strikethrough text |
| Code | Inline code |
Toolbar Visibility Modes
The toolbar supports multiple display modes controlled via props:enableRichTextEditor | hideRichTextFormattingOptions | Result |
|---|---|---|
false | - | Plain text, no formatting UI |
true | true | Toolbar always visible above input |
true | false | No toolbar UI, only text selection menu items work |
Text Selection Menu Items
On React Native, theshowTextSelectionMenuItems prop controls whether Bold, Italic, Underline, and Strikethrough options appear in the native text selection context menu (long-press popup). This is enabled by default.
Enter Key Behavior (Android Only)
TheenterKeyBehavior prop controls what happens when the Enter key is pressed on Android. On iOS, Enter always inserts a new line.
Toolbar Configuration Examples
Auto-Expanding Input
The CompactMessageComposer input auto-expands as the user types, up to a configurable maximum.| Prop | Type | Default | Description |
|---|---|---|---|
maxLines | number | 5 | Maximum lines before scrolling is enabled |
minInputHeight | number | 40 | Minimum height for the input in pixels |
maxInputHeight | number | 144 (calculated from maxLines) | Maximum height for the input. Overrides maxLines if both provided |
Custom View Slots
Each slot replaces a section of the default UI. Slots that accept parameters receive the relevant data for customization.| Slot | Signature | Replaces |
|---|---|---|
HeaderView | ({ user, group }) => JSX.Element | Area above the composer input |
FooterView | ({ user, group }) => JSX.Element | Area below the composer input |
AuxiliaryButtonView | ({ user, group, composerId }) => JSX.Element | Sticker button area |
SecondaryButtonView | ({ user, group, composerId }) => JSX.Element | Attachment button area |
SendButtonView | ({ user, group, composerId }) => JSX.Element | Send button |
attachmentOptions | CometChatMessageComposerAction[] | Default attachment options list |
addAttachmentOptions | CometChatMessageComposerAction[] | Additional attachment options appended to defaults |
textFormatters | CometChatTextFormatter[] | Text formatting in composer |
textFormatters
Custom text formatters for the composer input. To configure the existing Mentions look and feel check out CometChatMentionsFormatter.attachmentOptions
Override the default attachment options with custom actions.addAttachmentOptions
Extends the default attachment options with additional actions.AuxiliaryButtonView
Replace the sticker button area with a custom view.The CompactMessageComposer Component utilizes the AuxiliaryButton to provide sticker functionality. Overriding the AuxiliaryButton will replace the sticker functionality.
SendButtonView
Replace the send button with a custom view.HeaderView
Custom view above the composer input.FooterView
Custom view below the composer input.Styling
Using thestyle prop 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.
Visibility Props
| Property | Description | Code |
|---|---|---|
user | User object for 1-on-1 conversation | user={chatUser} |
group | Group object for group conversation | group={chatGroup} |
disableTypingEvents | Disable/enable typing events | disableTypingEvents={true} |
disableSoundForOutgoingMessages | Toggle sound for outgoing messages | disableSoundForOutgoingMessages={true} |
initialComposertext | Set predefined text | initialComposertext="Your custom text" |
placeHolderText | Placeholder text for the input | placeHolderText="Type a message..." |
customSoundForOutgoingMessage | Custom sound for outgoing messages | customSoundForOutgoingMessage="your-sound" |
hideVoiceRecordingButton | Hide voice recording option | hideVoiceRecordingButton={true} |
hideCameraOption | Hide camera option from attachments | hideCameraOption={true} |
hideImageAttachmentOption | Hide image attachment option | hideImageAttachmentOption={true} |
hideVideoAttachmentOption | Hide video attachment option | hideVideoAttachmentOption={true} |
hideAudioAttachmentOption | Hide audio attachment option | hideAudioAttachmentOption={true} |
hideFileAttachmentOption | Hide file attachment option | hideFileAttachmentOption={true} |
hidePollsAttachmentOption | Hide polls attachment option | hidePollsAttachmentOption={true} |
hideCollaborativeDocumentOption | Hide collaborative document option | hideCollaborativeDocumentOption={true} |
hideCollaborativeWhiteboardOption | Hide collaborative whiteboard option | hideCollaborativeWhiteboardOption={true} |
hideAttachmentButton | Hide attachment button | hideAttachmentButton={true} |
hideStickersButton | Hide stickers button | hideStickersButton={true} |
hideSendButton | Hide send button | hideSendButton={true} |
hideAuxiliaryButtons | Hide auxiliary buttons | hideAuxiliaryButtons={true} |
disableMentions | Disable mentions functionality | disableMentions={true} |
disableMentionAll | Disable @all mention | disableMentionAll={true} |
mentionAllLabel | Custom label for @all mention | mentionAllLabel="everyone" |
imageQuality | Image quality for camera (1-100) | imageQuality={50} |
auxiliaryButtonsAlignment | Alignment of auxiliary buttons | auxiliaryButtonsAlignment="right" |
enableRichTextEditor | Enable/disable rich text formatting | enableRichTextEditor={true} |
hideRichTextFormattingOptions | Always-visible toolbar mode | hideRichTextFormattingOptions={true} |
showTextSelectionMenuItems | Formatting in native text selection menu | showTextSelectionMenuItems={true} |
enterKeyBehavior | Android Enter key behavior | enterKeyBehavior={EnterKeyBehavior.SendMessage} |
maxLines | Maximum lines before scrolling | maxLines={3} |
minInputHeight | Minimum input height in pixels | minInputHeight={36} |
maxInputHeight | Maximum input height in pixels | maxInputHeight={120} |
maxMentionLimit | Maximum mentions per message | maxMentionLimit={5} |
Configuration
SingleLineMessageComposerConfiguration can be used to pass configuration when embedding the CompactMessageComposer inside other components:
Next Steps
Message Composer
Full-featured multi-line message composer component
Message List
Display the list of messages in a conversation
Mentions Formatter
Implement @mentions in your chat application
Component Styling
Customize the appearance of UI Kit components