CometChatTextFormatter class with the same API pattern:
- Kotlin XML:
com.cometchat.uikit.kotlin.shared.formatters.CometChatTextFormatter - Jetpack Compose:
com.cometchat.uikit.compose.presentation.shared.formatters.CometChatTextFormatter
CometChatTextFormatter API
The abstract class takes atrackingCharacter that triggers the formatter when typed in the composer (e.g., @ for mentions, # for hashtags).
Key Override Methods
| Method | Purpose |
|---|---|
search(context, queryString) | Called when the user types after the tracking character. Fetch and display suggestions. |
onScrollToBottom() | Called when the user scrolls to the bottom of the suggestion list. Use for pagination. |
prepareLeftMessageBubbleSpan(context, message, spannable) | Apply spans to text in incoming message bubbles. |
prepareRightMessageBubbleSpan(context, message, spannable) | Apply spans to text in outgoing message bubbles. |
prepareComposerSpan(context, message, spannable) | Apply spans to text in the message composer. |
prepareConversationSpan(context, message, spannable) | Apply spans to the last message preview in the conversation list. |
handlePreMessageSend(context, message) | Modify a message before it’s sent (attach metadata, transform text). |
onItemClick(context, suggestionItem, user, group) | Called when the user selects a suggestion item. |
Suggestion System
| Method | Description |
|---|---|
setSuggestionItemList(items) | Set the list of suggestions to display |
setShowLoadingIndicator(show) | Show/hide a loading spinner in the suggestion dropdown |
setDisableSuggestions(disable) | Disable the suggestion dropdown entirely |
Example: Custom Hashtag Formatter
- Kotlin (XML Views)
- Jetpack Compose
Registering Formatters
- Kotlin (XML Views)
- Jetpack Compose
Built-in Formatter: CometChatMentionsFormatter
The UI Kit includesCometChatMentionsFormatter as a built-in formatter that handles @mention detection, user suggestion lists, and spannable highlighting. It’s automatically added to components when mentions are enabled.
Each module has its own implementation:
- Kotlin XML:
com.cometchat.uikit.kotlin.shared.formatters.CometChatMentionsFormatter - Jetpack Compose:
com.cometchat.uikit.compose.presentation.shared.formatters.CometChatMentionsFormatter
Related
- Mentions Formatter Guide — Built-in mentions formatter reference.
- Customization Overview — See all customization categories.