Renamed in v6. v5’s
MessageTemplate API (CometChatMessageTemplate, setTemplates,
setType, setCategory, setBubbleView, setMessageReceipt) does not ship in
com.cometchat:chatuikit-kotlin-android:6.0.5 — verified against the published artifact. Bubble
customization is now BubbleFactory. If you are migrating, see
Upgrading from v5.BubbleFactory decides how one message category/type is rendered inside the
MessageList. You subclass it, say which messages it handles, and
supply the view. Everything you do not override keeps the kit’s default rendering.
When to Use This
- Render a custom message type (a contact card, an order receipt, a poll)
- Replace how a built-in type renders (text, image, video)
- Replace the whole bubble rather than just its content area
- Add an avatar / header / footer / thread view to a bubble
Prerequisites
- CometChat Android UI Kit dependency added
CometChatUIKit.initFromSettings()completed and a user logged in- A
CometChatMessageListon screen
Quick Start
- Kotlin (XML Views)
- Jetpack Compose
ContactBubbleFactory.kt
MessageActivity.kt
Core Concepts
The factory key is category + type
getCategory() and getType() are how the list decides which factory renders a message. Use the
SDK constants for built-ins (CometChatConstants.CATEGORY_MESSAGE with MESSAGE_TYPE_TEXT,
MESSAGE_TYPE_IMAGE, …) and CATEGORY_CUSTOM with your own type string for custom messages. A
message with no matching factory falls back to the kit’s own rendering.
create/bind is a recycling contract (Views)
createContentView() runs once per recycled view and the message is deliberately not available
there — only the factory key. bindContentView() runs every time a message is displayed in that
view. Building views in bind (or caching per-message state in create) is the usual cause of
bubbles showing the wrong message after scrolling.
Compose has no such split: getContentView() receives the message and returns a composable.
Content view vs whole bubble
Optional view slots
All are optional; returnnull (Views) or leave the default (Compose) to keep the kit’s own.
Creating a new custom message type
- Send the message with the SDK using
CometChatConstants.CATEGORY_CUSTOMand your own type string (see Custom Messages). - Write a
BubbleFactorywhosegetCategory()/getType()match exactly. - Register it with
setBubbleFactories(...)(Views) or thebubbleFactoriesparameter (Compose).
Next Steps
- Message List — where factories are registered
- Message Bubble Styling — styling without replacing views
- Upgrading from v5 — the
MessageTemplate→BubbleFactorymove