Skip to main content
{
  "component": "CometChatMessageComposer",
  "package": "CometChatUIKitSwift",
  "import": "import CometChatUIKitSwift\nimport CometChatSDK",
  "inherits": "UIView",
  "description": "Rich text input for composing and sending text, media, attachments, mentions, voice notes, and custom messages.",
  "props": {
    "data": {
      "user": "User? - recipient user for direct messaging",
      "group": "Group? - recipient group for group messaging",
      "parentMessageId": "Int? - parent message ID for thread replies"
    },
    "callbacks": {
      "onSendButtonClick": "(BaseMessage) -> Void",
      "onTextChangedListener": "(String) -> Void",
      "onError": "(CometChatException) -> Void"
    },
    "visibility": {
      "hideAttachmentButton": "Bool (default: false)",
      "hideVoiceRecordingButton": "Bool (default: false)",
      "hideStickersButton": "Bool (default: false)",
      "hideSendButton": "Bool (default: false)",
      "hideAIButton": "Bool (default: false)",
      "hideHeaderView": "Bool (default: false)",
      "hideFooterView": "Bool (default: false)"
    },
    "behavior": {
      "disableTypingEvents": "Bool (default: false)",
      "disableMentions": "Bool (default: false)",
      "placeholderText": "String (default: 'Type a message...')"
    },
    "viewSlots": {
      "headerView": "(User?, Group?) -> UIView",
      "footerView": "(User?, Group?) -> UIView",
      "sendButtonView": "(User?, Group?) -> UIView",
      "auxillaryButtonView": "(User?, Group?) -> UIView",
      "attachmentOptions": "(User?, Group?, UIViewController?) -> [CometChatMessageComposerAction]"
    }
  },
  "methods": {
    "set(user:)": "Sets recipient user",
    "set(group:)": "Sets recipient group",
    "set(parentMessageId:)": "Sets parent message for threads",
    "setInitialComposerText(_:)": "Pre-fills composer text",
    "set(textFormatter:)": "Sets custom text formatter",
    "setDisableMentionAll(_:)": "Disables @all mentions",
    "setMentionAllLabel(_:_:)": "Customizes @all label"
  },
  "styling": {
    "globalStyle": "CometChatMessageComposer.style",
    "instanceStyle": "MessageComposerStyle",
    "subStyles": ["MediaRecorderStyle", "AttachmentSheetStyle", "SuggestionsStyle", "AIOptionsStyle", "MentionStyle"]
  }
}
FieldValue
ComponentCometChatMessageComposer
PackageCometChatUIKitSwift
InheritsUIView
The CometChatMessageComposer component enables users to write and send messages including text, images, videos, audio, files, and custom messages. It supports attachments, voice recording, stickers, mentions, and AI-powered features.

Where It Fits

CometChatMessageComposer provides a rich text input with attachment, emoji, voice recording, sticker, and send controls. Wire it alongside CometChatMessageHeader and CometChatMessageList to build a standard chat view.
import UIKit
import CometChatUIKitSwift
import CometChatSDK

class ChatViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        CometChat.getUser(UID: "uid") { user in
            DispatchQueue.main.async {
                let header = CometChatMessageHeader()
                header.set(user: user)
                
                let messageList = CometChatMessageList()
                messageList.set(user: user)
                
                let composer = CometChatMessageComposer()
                composer.set(user: user)
                
                // Add to view hierarchy and layout
            }
        } onError: { error in
            print("Error: \(error?.errorDescription ?? "")")
        }
    }
}

Minimal Render

import CometChatUIKitSwift

let composer = CometChatMessageComposer()
composer.set(user: user)

Actions and Events

Callback Props

onSendButtonClick

Fires when the send button is clicked. Overrides the default send behavior.
import CometChatUIKitSwift

let composer = CometChatMessageComposer()
composer.set(user: user)

composer.set(onSendButtonClick: { message in
    print("Custom send: \(message.id)")
})

onTextChangedListener

Fires as the user types in the composer input.
import CometChatUIKitSwift

let composer = CometChatMessageComposer()
composer.set(user: user)

composer.set(onTextChangedListener: { text in
    print("Text changed: \(text)")
})

onError

Fires on internal errors.
import CometChatUIKitSwift

let composer = CometChatMessageComposer()
composer.set(user: user)

composer.set(onError: { error in
    print("Composer error: \(error.errorDescription)")
})

SDK Events (Real-Time, Automatic)

The component internally handles typing indicators and message sending. No manual SDK listener attachment needed.

Custom View Slots

SlotSignatureReplaces
headerView(User?, Group?) -> UIViewArea above the composer input
footerView(User?, Group?) -> UIViewArea below the composer input
sendButtonView(User?, Group?) -> UIViewSend button
auxillaryButtonView(User?, Group?) -> UIViewSticker and AI button area
attachmentOptions(User?, Group?, UIViewController?) -> [CometChatMessageComposerAction]Default attachment options list

headerView

Custom view above the composer input.
import UIKit
import CometChatUIKitSwift

let composer = CometChatMessageComposer()
composer.set(user: user)

composer.set(headerView: { user, group in
    let view = UIView()
    view.backgroundColor = UIColor.purple.withAlphaComponent(0.1)
    
    let label = UILabel()
    label.text = "User has paused their notifications"
    label.font = UIFont.systemFont(ofSize: 14)
    view.addSubview(label)
    
    return view
})

footerView

Custom view below the composer input.
import UIKit
import CometChatUIKitSwift

let composer = CometChatMessageComposer()
composer.set(user: user)

composer.set(footerView: { user, group in
    let view = UIView()
    
    let label = UILabel()
    label.text = "Messages are end-to-end encrypted"
    label.font = UIFont.systemFont(ofSize: 12)
    label.textColor = .secondaryLabel
    view.addSubview(label)
    
    return view
})

sendButtonView

Replace the send button.
import UIKit
import CometChatUIKitSwift

let composer = CometChatMessageComposer()
composer.set(user: user)

composer.set(sendButtonView: { user, group in
    let button = UIButton(type: .system)
    button.setImage(UIImage(systemName: "paperplane.fill"), for: .normal)
    button.tintColor = .systemBlue
    return button
})

auxillaryButtonView

Replace the sticker and AI button area.
import UIKit
import CometChatUIKitSwift

let composer = CometChatMessageComposer()
composer.set(user: user)

composer.set(auxillaryButtonView: { user, group in
    let stackView = UIStackView()
    stackView.axis = .horizontal
    stackView.spacing = 8
    
    let aiButton = UIButton(type: .system)
    aiButton.setImage(UIImage(systemName: "sparkles"), for: .normal)
    
    let emojiButton = UIButton(type: .system)
    emojiButton.setImage(UIImage(systemName: "face.smiling"), for: .normal)
    
    stackView.addArrangedSubview(aiButton)
    stackView.addArrangedSubview(emojiButton)
    
    return stackView
})

attachmentOptions

Override the default attachment options.
import UIKit
import CometChatUIKitSwift

let composer = CometChatMessageComposer()
composer.set(user: user)

composer.set(attachmentOptions: { user, group, controller in
    return [
        CometChatMessageComposerAction(
            id: "photo",
            text: "Photo",
            startIcon: UIImage(systemName: "photo"),
            startIconTint: .systemBlue,
            onActionClick: { print("Photo selected") }
        ),
        CometChatMessageComposerAction(
            id: "camera",
            text: "Camera",
            startIcon: UIImage(systemName: "camera"),
            startIconTint: .systemGreen,
            onActionClick: { print("Camera selected") }
        ),
        CometChatMessageComposerAction(
            id: "location",
            text: "Location",
            startIcon: UIImage(systemName: "location"),
            startIconTint: .systemRed,
            onActionClick: { print("Location selected") }
        )
    ]
})

Common Patterns

Thread composer

let composer = CometChatMessageComposer()
composer.set(user: user)
composer.set(parentMessageId: parentMessage.id)

Minimal composer — text only

let composer = CometChatMessageComposer()
composer.set(user: user)
composer.hideAttachmentButton = true
composer.hideVoiceRecordingButton = true
composer.hideStickersButton = true
composer.hideAIButton = true

Pre-filled text

let composer = CometChatMessageComposer()
composer.set(user: user)
composer.setInitialComposerText("Hello! ")
composer.placeholderText = "Type a message..."

Disable typing indicators

let composer = CometChatMessageComposer()
composer.set(user: user)
composer.disableTypingEvents = true

Disable mentions

let composer = CometChatMessageComposer()
composer.set(user: user)
composer.disableMentions = true

Custom send button action

let composer = CometChatMessageComposer()
composer.set(user: user)

composer.set(onSendButtonClick: { message in
    print("Sending message: \(message)")
})

Styling

Style Hierarchy

  1. Global styles (CometChatMessageComposer.style) apply to all instances
  2. Instance styles override global for specific instances

Global Level Styling

import CometChatUIKitSwift

CometChatMessageComposer.style.backgroundColor = .systemBackground
CometChatMessageComposer.style.activeSendButtonImageBackgroundColor = .systemBlue
CometChatMessageComposer.style.attachmentImageTint = .systemGray
CometChatMessageComposer.style.voiceRecordingImageTint = .systemGray

Instance Level Styling

import CometChatUIKitSwift

var customStyle = MessageComposerStyle()
customStyle.backgroundColor = UIColor(red: 0.95, green: 0.95, blue: 0.97, alpha: 1.0)
customStyle.activeSendButtonImageBackgroundColor = .systemOrange
customStyle.composeBoxBackgroundColor = .white
customStyle.composeBoxBorderColor = .systemGray4

let composer = CometChatMessageComposer()
composer.style = customStyle

Key Style Properties

PropertyTypeDescription
backgroundColorUIColorBackground color
borderWidthCGFloatBorder width
borderColorUIColorBorder color
cornerRadiusCometChatCornerStyle?Corner radius
placeHolderTextFontUIFontPlaceholder font
placeHolderTextColorUIColorPlaceholder color
textFiledColorUIColorInput text color
textFiledFontUIFontInput text font
sendButtonImageUIImage?Send button icon
sendButtonImageTintUIColorSend button tint
activeSendButtonImageBackgroundColorUIColorActive send button background
inactiveSendButtonImageBackgroundColorUIColorInactive send button background
composeBoxBackgroundColorUIColorCompose box background
composeBoxBorderColorUIColorCompose box border color
composeBoxBorderWidthCGFloatCompose box border width
attachmentImageUIImage?Attachment button icon
attachmentImageTintUIColorAttachment icon tint
voiceRecordingImageUIImage?Voice recording icon
voiceRecordingImageTintUIColorVoice recording tint

Sub-Component Styles

PropertyTypeDescription
mediaRecorderStyleMediaRecorderStyleVoice recording interface
attachmentSheetStyleAttachmentSheetStyleAttachment options sheet
suggestionsStyleSuggestionsStyleMentions suggestions view
aiOptionsStyleAIOptionsStyleAI options menu
mentionStyleMentionStyleMentions appearance

Customization Matrix

What to changeWhereProperty/API
Override send behaviorCallbackset(onSendButtonClick:)
Track text inputCallbackset(onTextChangedListener:)
Toggle visibilityPropshide<Feature> boolean props
Custom attachmentsView Slotset(attachmentOptions:)
Replace UI sectionsView Slotset(headerView:), set(sendButtonView:)
Change colors, fontsStyleMessageComposerStyle properties

Props

All props are optional. Sorted alphabetically.
PropertyTypeDefaultDescription
disableMentionsBoolfalseDisables the @mention feature
disableSoundForMessagesBoolfalseDisables sound when sending messages
disableTypingEventsBoolfalseDisables sending typing indicators
hideAIButtonBoolfalseHides the AI button
hideAttachmentButtonBoolfalseHides the attachment button
hideAudioAttachmentOptionBoolfalseHides the audio attachment option
hideCollaborativeDocumentOptionBoolfalseHides the collaborative document option
hideCollaborativeWhiteboardOptionBoolfalseHides the collaborative whiteboard option
hideFileAttachmentOptionBoolfalseHides the file attachment option
hideFooterViewBoolfalseHides the footer view
hideHeaderViewBoolfalseHides the header view
hideImageAttachmentOptionBoolfalseHides the image attachment option
hidePollsOptionBoolfalseHides the polls option
hideSendButtonBoolfalseHides the send button
hideStickersButtonBoolfalseHides the stickers button
hideVideoAttachmentOptionBoolfalseHides the video attachment option
hideVoiceRecordingButtonBoolfalseHides the voice recording button
maxLineInt5Maximum lines before scrolling
placeholderTextString"Type a message..."Placeholder text
textFormatters[CometChatTextFormatter][]Custom text formatters

Methods

set(textFormatter:)

Sets a custom text formatter for the composer input.
let composer = CometChatMessageComposer()
let mentionFormatter = MentionTextFormatter(trackingCharacter: "@")
composer.set(textFormatter: mentionFormatter)

setDisableMentionAll(_:)

Disables or enables the @all mention feature that notifies all group members.
let composer = CometChatMessageComposer()
composer.setDisableMentionAll(true)

setMentionAllLabel(::)

Customizes the label displayed for @all mentions in the suggestions list.
let composer = CometChatMessageComposer()
composer.setMentionAllLabel("Everyone", "Notify all members in this group")