Skip to main content
Text formatters let you process message text with tracking characters, suggestion lists, and spannable transformations. Use them to add hashtag detection, custom mentions, link previews, or any text pattern processing. Both modules have their own 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 a trackingCharacter that triggers the formatter when typed in the composer (e.g., @ for mentions, # for hashtags).

Key Override Methods

Suggestion System


Example: Custom Hashtag Formatter


Registering Formatters


Built-in Formatter: CometChatMentionsFormatter

The UI Kit includes CometChatMentionsFormatter 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
See the Mentions Formatter Guide for details.