Skip to main content
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.
A 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 CometChatMessageList on screen

Quick Start

ContactBubbleFactory.kt
Register it on the list:
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; return null (Views) or leave the default (Compose) to keep the kit’s own.

Creating a new custom message type

  1. Send the message with the SDK using CometChatConstants.CATEGORY_CUSTOM and your own type string (see Custom Messages).
  2. Write a BubbleFactory whose getCategory()/getType() match exactly.
  3. Register it with setBubbleFactories(...) (Views) or the bubbleFactories parameter (Compose).
Messages of a type with no registered factory render with the kit’s default custom-message bubble, so register the factory on every screen that shows those messages.

Next Steps