- SwiftUI (
CometChatSwiftUI) uses aBubbleFactory. You write a struct that names aMessageKindand returns SwiftUI views. - UIKit (
CometChatUIKit) uses aCometChatMessageTemplate. You build a template with a category, a type and closures that returnUIViews.
AI Integration Quick Reference
AI Integration Quick Reference
When to Use This
- Draw a custom message type — a contact card, an order receipt, a location.
- Replace how a built-in type is drawn — text, image, file …
- Replace the whole row rather than only the bubble’s content.
- Change one region of a bubble — the avatar, the sender name, the status line, the reactions — for one kind only.
Prerequisites
- The
CometChatSwiftUIorCometChatUIKitproduct added fromhttps://github.com/cometchat/cometchat-uikit-ios.git(from6.0.0-beta.1, iOS 18). - The Kit initialised and a user logged in.
- A
CometChatMessageListon screen.
Quick Start
This example draws a custom message of typecontact as a card with a name and a phone number.
- SwiftUI
- UIKit
Write a factory: name the kind, and return the content.Register it on the list, and ask the list to fetch your type:
ContactBubbleFactory.swift
ChatScreen.swift
The request builder replaces the Kit’s request whole. The list adds the user or group; set
the types, categories, page size,
hideReplies and — for a thread — the parent message id
yourself. Live messages are filtered by the same types, so a type missing here never shows.Core Concepts
The key is category + type
A message is matched to a factory or template by its category and type — the SDK’s
message / text, custom / extension_poll, or custom / your own type. One is kept per
kind, and the last registered wins, so registering one for a built-in kind replaces the
Kit’s bubble for that kind.
- SwiftUI
- UIKit
The key is the factory’s
kind, a MessageKind. The built-in kinds are constants —
.text, .image, .video, .audio, .voiceNote, .file, .sticker, .poll, .meeting,
.document, .whiteboard, .card, .aiAssistant, .groupAction, .audioCall, .videoCall.
A voice note is its own kind, .voiceNote, separate from .audio.What each slot receives
- SwiftUI
- UIKit
Every slot receives the message as the Kit’s value type,
ChatMessage, and its
MessageAlignment — .incoming, .outgoing or .centred. A custom message’s customData
is message.custom?.data, a dictionary of SuggestionItem.DataValue (.string, .int,
.double, .bool, .array, .object, .null). The resolved bubble style is in the
environment as \.cometChatMessageBubbleStyle.There is no create/bind split: the list asks the factory for a view each time it draws the
row, and SwiftUI diffs it. A factory must be Sendable — a struct with Sendable stored
properties is.Content vs the whole bubble
- SwiftUI
- UIKit
Because
content is required, a factory for a built-in kind replaces the built-in content.
To keep it and change only one region, delegate content to the built-in factory:.groupAction, .audioCall, .videoCall — gives
those rows the full bubble chrome: name, status line and reactions.
Optional view slots
Every slot is optional. Leave it out, or returnnil, to keep the Kit’s view for that region.
- SwiftUI
- UIKit
style(for:) is asked per alignment and wins over the list’s bubble styles:leadingView:, headerView:, contentView: … — apply to
every kind and outrank a factory’s.Bubbles outside the list
The thread header, Message Information and Pinned Messages draw messages with the same bubbles. Hand them your factories or templates too.- SwiftUI
- UIKit
CometChatMessageInformation, opened from the list’s Info option, gets the list’sbubbleFactoriesautomatically.CometChatThreadHeader(parentMessage:bubbleFactories:)andCometChatPinnedMessages(user:group:bubbleFactories:)take them as an argument.CometChatMessageBubble(message:alignment:factory:)draws one message anywhere.
Creating a new custom message type
- Send the message as a
CustomMessagewith your own type. Send it through the Kit — notCometChat.sendCustomMessage— so the Kit’smessageSentevent goes out with it. - Draw it with a
BubbleFactory(SwiftUI) orCometChatMessageTemplate(UIKit) whose category iscustomand whose type matches exactly. - Fetch it: add the type to the list’s
messagesRequestBuilder. - Register it on every screen that shows those messages — the list, and the thread header.
- SwiftUI
- UIKit
Next Steps
Message List
Where bubbles are registered, and the list-wide view slots
Message Bubble Styling
Style bubbles without replacing views
Threaded Messages Header
The parent message, drawn with your bubbles
Upgrading from v5
v5 templates in v6, and what replaced the DataSource chain