Skip to main content

Goal

By the end of this guide you will have a color button in the composer’s rich-text toolbar. The user selects some text, taps a swatch, and the text turns that color — in the composer while typing, and in the message bubble after it is sent. In React Native you do not need to write a text formatter for this. Text color is part of the UI Kit’s built-in rich-text format, so the work splits into two small pieces:
  1. Authoring — a button in the composer’s ToolbarTrailingButtonsView slot that applies a color to the current selection through the composer handle.
  2. Rendering — nothing to do. The UI Kit already renders colored text wherever it formats rich text.
This guide colors text with the built-in rich-text format. To build your own inline pattern — hashtags, keywords, custom tokens — see the Text Formatter Base Class guide instead.

Prerequisites

  • Completed the Integration Guide
  • A chat screen using CometChatMessageList and CometChatCompactMessageComposer
ToolbarTrailingButtonsView exists on CometChatCompactMessageComposer only. CometChatMessageComposer has no formatting toolbar, so there is nowhere to mount the button.

Step 1: The Toolbar Button

ToolbarTrailingButtonsView renders your views at the end of the formatting toolbar, after a divider. It is a render function, and besides user, group and composerId it receives a composer handle — the same controls the built-in Bold and Italic buttons use. The toolbar shows an A and a . Tapping A swaps them for a row of color swatches; tapping a swatch colors the selection. removes the color from the selection. File: ChatScreen.tsx
Keep the picker’s state in your screen. The composer mounts ToolbarTrailingButtonsView as a component, and an inline render function is a new function every time your screen re-renders, so whatever it returns is remounted. State held inside it — an open flag in a child component, for example — resets, and the picker closes on its own.
Keep the swatches inside the toolbar — do not open a Modal. A modal takes focus from the text input, which collapses the selection before applyInlineStyle runs, so nothing gets colored. Views rendered inline in the toolbar keep the selection alive, the same way the built-in buttons do.

Step 2: Try It

The slot lives inside the formatting toolbar, so it only renders while the toolbar is visible: enableRichTextEditor must be true and hideRichTextFormattingOptions must be false. Both are the defaults, so the screen above needs neither. The user selects “world”, taps A, picks red, and the word turns red in the composer. With no selection, the color applies to whatever they type next, the same way Bold does. On send, the message text becomes Hello <color=#e11d48>world</color>.

Step 3: Where the Color Shows Up

There is nothing to register. The UI Kit’s rich-text formatting reads the color markup and renders it as colored text on the surfaces that format message text, including:
  • Message bubbles in CometChatMessageList — and therefore in threads and in CometChatPinnedMessages, which render the same bubbles
  • The last-message subtitle in CometChatConversations
  • Results in CometChatSearch
Unlike the React UI Kit, you do not add a formatter to each surface — the color is not a custom marker, so every UI Kit surface that renders rich text already understands it.

What Gets Sent

Use "color" for anything the recipient should see. "backgroundColor" is accepted by applyInlineStyle but never leaves the device.

How It Round-Trips

The markup is plain text on the message, so it survives storage and delivery untouched. Every UI Kit surface that renders rich text turns it back into color on its own.

The composer Handle

The handle your button receives. Every method acts on the live composer input. getActiveStyles() does not report the current color, so a color button cannot show which swatch is active.

Next Steps