From 0c01a26a39e9d355697e6bd8e652f740cf53399d Mon Sep 17 00:00:00 2001 From: Ashfaq Ali Date: Wed, 4 Mar 2026 14:53:19 +0530 Subject: [PATCH] Add docs for single line composer --- docs.json | 1 + ui-kit/android/single-line-composer.mdx | 686 ++++++++++++++++++++++++ 2 files changed, 687 insertions(+) create mode 100644 ui-kit/android/single-line-composer.mdx diff --git a/docs.json b/docs.json index 5e6b79214..7c3e814c2 100644 --- a/docs.json +++ b/docs.json @@ -1561,6 +1561,7 @@ "ui-kit/android/message-header", "ui-kit/android/message-list", "ui-kit/android/message-composer", + "ui-kit/android/single-line-composer", "ui-kit/android/threaded-messages-header", "ui-kit/android/incoming-call", "ui-kit/android/outgoing-call", diff --git a/ui-kit/android/single-line-composer.mdx b/ui-kit/android/single-line-composer.mdx new file mode 100644 index 000000000..5a89626a5 --- /dev/null +++ b/ui-kit/android/single-line-composer.mdx @@ -0,0 +1,686 @@ +--- +title: "Single Line Composer" +description: "A compact, single-line message input component with rich text formatting, attachments, mentions, and voice recording support." +--- + +## Overview + +CometChatSingleLineComposer is a [Component](/ui-kit/android/components-overview#components) that provides a compact, single-line message input designed for chat applications. It offers a streamlined interface with optional rich text formatting capabilities, supporting bold, italic, strikethrough, code, links, lists, and blockquotes. + +Features such as **Rich Text Formatting**, **Attachments**, **Message Editing**, **Mentions**, **Stickers**, and **Voice Recording** are supported. + + + + + +## Usage + +### Integration + +The following code snippet illustrates how you can directly incorporate the SingleLineComposer component into your `layout.xml` file. + +```xml + +``` + + + +The SingleLineComposer is responsible for managing runtime permissions. To ensure the **ActivityResultLauncher** is properly initialized, its object should be created in the **onCreate** state of an activity. To ensure that the composer is loaded within the fragment, it is important to make sure that the fragment is loaded in the `onCreate` state of the activity. + + + +### Actions + +[Actions](/ui-kit/android/components-overview#actions) dictate how a component functions. They are divided into two types: Predefined and User-defined. You can override either type, allowing you to tailor the behavior of the component to fit your specific needs. + +##### setOnSendClickListener + +The `setOnSendClickListener` event gets activated when the send message button is clicked. It has a predefined function of sending messages entered in the composer. However, you can override this action with the following code snippet. + + + +```java +singleLineComposer.setOnSendClickListener(new CometChatSingleLineComposer.SendButtonClickListener() { + @Override + public void onSendClick(Context context, BaseMessage baseMessage) { + Toast.makeText(context, "OnSendButtonClicked ..", Toast.LENGTH_SHORT).show(); + } +}); +``` + + + + +```kotlin +singleLineComposer.setOnSendClickListener( + CometChatSingleLineComposer.SendButtonClickListener { context, baseMessage -> + Toast.makeText(context, "OnSendButtonClicked ..", Toast.LENGTH_SHORT).show() + } +) +``` + + + + + +##### setOnErrorListener + +This action doesn't change the behavior of the component but rather listens for any errors that occur in the SingleLineComposer component. + + + +```java +singleLineComposer.setOnErrorListener(new CometChatSingleLineComposer.OnErrorListener() { + @Override + public void onError(Exception e) { + // Your Exception Handling code. + } +}); +``` + + + + +```kotlin +singleLineComposer.setOnErrorListener( + CometChatSingleLineComposer.OnErrorListener { e -> + // Your Exception Handling code. + } +) +``` + + + + + + +##### setOnTextChangeListener + +Function triggered whenever the message input's text value changes, enabling dynamic text handling. + + + +```java +singleLineComposer.setOnTextChangeListener(new CometChatSingleLineComposer.OnTextChangeListener() { + @Override + public void onTextChange(String text) { + // Handle text change + } +}); +``` + + + + +```kotlin +singleLineComposer.setOnTextChangeListener( + CometChatSingleLineComposer.OnTextChangeListener { text -> + // Handle text change + } +) +``` + + + + + +##### setOnAttachmentClickListener + +This action is triggered when the attachment button is clicked. You can override the default attachment sheet behavior with a custom implementation. + + + +```java +singleLineComposer.setOnAttachmentClickListener(new CometChatSingleLineComposer.OnAttachmentClickListener() { + @Override + public void onAttachmentClick() { + // Your custom attachment handling + } +}); +``` + + + + +```kotlin +singleLineComposer.setOnAttachmentClickListener( + CometChatSingleLineComposer.OnAttachmentClickListener { + // Your custom attachment handling + } +) +``` + + + + + +*** + +### Filters + +SingleLineComposer component does not have any available filters. + +*** + +### Events + +[Events](/ui-kit/android/components-overview#events) are emitted by a `Component`. By using event you can extend existing functionality. Being global events, they can be applied in Multiple Locations and are capable of being Added or Removed. + +The SingleLineComposer Component does not emit any events of its own. + +*** + +## Customization + +To fit your app's design requirements, you can customize the appearance of the SingleLineComposer component. We provide exposed methods that allow you to modify the experience and behavior according to your specific needs. + +### Style + +Using Style you can customize the look and feel of the component in your app. These parameters typically control elements such as the color, size, shape, and fonts used within the component. + + + + + +```html + + + + + + + + +``` + +```xml + + +``` + + + +```java +singleLineComposer.setStyle(R.style.CustomSingleLineComposerStyle); +``` + + + + +```kotlin +singleLineComposer.setStyle(R.style.CustomSingleLineComposerStyle) +``` + + + + + +*** + +### Functionality + +These are a set of small functional customizations that allow you to fine-tune the overall experience of the component. With these, you can change text, set custom icons, and toggle the visibility of UI elements. + +Below is a list of customizations along with corresponding code snippets + +| Property | Description | Code | +| ---------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- | +| **User** | Used to pass user object of which header specific details will be shown | `.setUser(user)` | +| **Group** | Used to pass group object of which header specific details will be shown | `.setGroup(group)` | +| **setParentMessageId** | Sets the parent message ID for threaded replies | `.setParentMessageId(long)` | +| **setPlaceholderText** | Sets the placeholder text for the input field | `.setPlaceholderText("Type a message...")` | +| **setMaxLines** | Maximum lines allowed to increase in the input field | `.setMaxLines(int)` | +| **setEnterKeyBehavior** | Determines the behavior of the Enter key. `SEND_MESSAGE` sends the message, `NEW_LINE` inserts a new line | `.setEnterKeyBehavior(EnterKeyBehavior.SEND_MESSAGE)` | +| **setText** | Used to set text programmatically | `.setText("Your_Text")` | +| **setEnableRichTextFormatting** | Master switch to enable or disable rich text formatting (bold, italic, etc.) | `.setEnableRichTextFormatting(boolean)` | +| **setRichTextFormattingOptionsVisibility** | Controls the visibility of the rich text formatting toolbar | `.setRichTextFormattingOptionsVisibility(View.VISIBLE)` | +| **setShowTextSelectionMenuItems** | Shows formatting options (Bold, Italic, Strikethrough, Code) in the text selection context menu | `.setShowTextSelectionMenuItems(true)` | +| **setDisableTypingEvents** | Used to disable/enable typing events, default false | `.setDisableTypingEvents(boolean)` | +| **setDisableSoundForMessages** | Used to toggle sound for outgoing messages | `.setDisableSoundForMessages(boolean)` | +| **setCustomSoundForMessages** | Used to give custom sounds to outgoing messages | `.setCustomSoundForMessages(R.raw.sound)` | +| **setDisableMentions** | Sets whether mentions in text should be disabled. Processes the text formatters. If there are text formatters available and the disableMentions flag is set to true, it removes any formatters that are instances of CometChatMentionsFormatter. | `.setDisableMentions(true)` | +| **setDisableMentionAll** | Controls whether group mentions like @all appear in suggestions | `.setDisableMentionAll(true)` | +| **setAttachmentButtonVisibility** | Hides the attachment button in the composer | `.setAttachmentButtonVisibility(View.VISIBLE)` | +| **setVoiceRecordingButtonVisibility** | Hides the voice recording button in the composer | `.setVoiceRecordingButtonVisibility(View.GONE)` | +| **setStickerButtonVisibility** | Hides the sticker button in the composer | `.setStickerButtonVisibility(View.GONE)` | +| **setAIButtonVisibility** | Hides the AI button in the composer | `.setAIButtonVisibility(View.GONE)` | +| **setSendButtonVisibility** | Hides the send button in the composer | `.setSendButtonVisibility(View.VISIBLE)` | +| **setCameraAttachmentOptionVisibility** | Controls whether camera attachments are allowed | `.setCameraAttachmentOptionVisibility(View.VISIBLE)` | +| **setImageAttachmentOptionVisibility** | Controls whether image attachments are allowed | `.setImageAttachmentOptionVisibility(View.VISIBLE)` | +| **setVideoAttachmentOptionVisibility** | Controls whether video attachments are allowed | `.setVideoAttachmentOptionVisibility(View.VISIBLE)` | +| **setAudioAttachmentOptionVisibility** | Controls whether audio attachments are allowed | `.setAudioAttachmentOptionVisibility(View.VISIBLE)` | +| **setFileAttachmentOptionVisibility** | Controls whether file attachments are allowed | `.setFileAttachmentOptionVisibility(View.VISIBLE)` | +| **setPollAttachmentOptionVisibility** | Controls whether polls can be shared | `.setPollAttachmentOptionVisibility(View.VISIBLE)` | +| **setCollaborativeDocumentOptionVisibility** | Controls whether collaborative documents can be shared | `.setCollaborativeDocumentOptionVisibility(View.VISIBLE)` | +| **setCollaborativeWhiteboardOptionVisibility** | Controls whether collaborative whiteboards can be shared | `.setCollaborativeWhiteboardOptionVisibility(View.VISIBLE)` | +| **setUseInlineAudioRecorder** | Switches between inline audio recorder (default) and bottom sheet recorder | `.setUseInlineAudioRecorder(boolean)` | + +*** + +### Advanced + +For advanced-level customization, you can set custom views to the component. This lets you tailor each aspect of the component to fit your exact needs and application aesthetics. You can create and define your views, layouts, and UI elements and then incorporate those into the component. + +*** + +#### setTextFormatters + +Assigns the list of text formatters. If the provided list is not null, it sets the list. Otherwise, it assigns the default text formatters retrieved from the data source. To configure the existing Mentions look and feel check out [CometChatMentionsFormatter](/ui-kit/android/mentions-formatter-guide) + +**Example** + + + + + +```xml themes.xml + +``` + + + +```java +// Initialize CometChatMentionsFormatter +CometChatMentionsFormatter mentionFormatter = new CometChatMentionsFormatter(context); + +// set style to customize composer mention text +mentionFormatter.setMessageComposerMentionTextStyle(context, R.style.CustomSingleLineComposerMentionsStyle); + +// This can be passed as an array of formatter in CometChatSingleLineComposer by using setTextFormatters method. +List textFormatters = new ArrayList<>(); +textFormatters.add(mentionFormatter); +singleLineComposer.setTextFormatters(textFormatters); +``` + + + + +```kotlin +// Initialize CometChatMentionsFormatter +val mentionFormatter = CometChatMentionsFormatter(context) +// set style to customize composer mention text +mentionFormatter.setMessageComposerMentionTextStyle(context, R.style.CustomSingleLineComposerMentionsStyle) + +// This can be passed as an array of formatter in CometChatSingleLineComposer by using setTextFormatters method. +val textFormatters: MutableList = ArrayList() +textFormatters.add(mentionFormatter) +singleLineComposer.setTextFormatters(textFormatters) +``` + + + + + +#### setAttachmentOptions + +By using `setAttachmentOptions()`, you can set a list of custom `MessageComposerActions` for the SingleLineComposer Component. This will override the existing list of `MessageComposerActions`. + + + +```java +singleLineComposer.setAttachmentOptions(actionList); +``` + + + + +```kotlin +singleLineComposer.setAttachmentOptions(actionList) +``` + + + + + +**Example** + + + + + +In this example, we are overriding the existing MessageComposerActions List with custom actions. + + + +```java +List actionList = new ArrayList<>(); + +CometChatMessageComposerAction action1 = new CometChatMessageComposerAction(); +action1.setTitle("Custom Option 1"); +action1.setIcon(R.drawable.ic_cp_1); +action1.setOnClick(new OnClick() { + @Override + public void onClick() { + Toast.makeText(context, "Custom Option 1 !!!", Toast.LENGTH_SHORT).show(); + } +}); +actionList.add(action1); + +CometChatMessageComposerAction action2 = new CometChatMessageComposerAction(); +action2.setTitle("Custom Option 2"); +action2.setIcon(R.drawable.ic_cp_2); +action2.setOnClick(new OnClick() { + @Override + public void onClick() { + Toast.makeText(context, "Custom Option 2 !!!", Toast.LENGTH_SHORT).show(); + } +}); +actionList.add(action2); + +singleLineComposer.setAttachmentOptions(actionList); +``` + + + + +```kotlin +val actionList = ArrayList() + +val action1 = CometChatMessageComposerAction() +action1.title = "Custom Option 1" +action1.icon = R.drawable.ic_cp_1 +action1.onClick = { + Toast.makeText(context, "Custom Option 1 !!!", Toast.LENGTH_SHORT).show() +} +actionList.add(action1) + +val action2 = CometChatMessageComposerAction() +action2.title = "Custom Option 2" +action2.icon = R.drawable.ic_cp_2 +action2.onClick = { + Toast.makeText(context, "Custom Option 2 !!!", Toast.LENGTH_SHORT).show() +} +actionList.add(action2) + +singleLineComposer.setAttachmentOptions(actionList) +``` + + + + + +*** + +#### setAuxiliaryButtonView + +You can insert a custom view into the SingleLineComposer component to add additional functionality using the following method. + + + +```java +singleLineComposer.setAuxiliaryButtonView(view); +``` + + + + +```kotlin +singleLineComposer.setAuxiliaryButtonView(view) +``` + + + + + +Please note that the SingleLineComposer Component utilizes the AuxiliaryButton to provide sticker functionality. Overriding the AuxiliaryButton will subsequently replace the sticker functionality. + +**Example** + + + + + +In this example, we'll be adding a custom button with click functionality. You'll first need to create a layout file and then inflate it inside the `.setAuxiliaryButtonView()` function. + + + +```java +ImageView imageView = new ImageView(this); +imageView.setImageResource(R.drawable.save_icon); +LinearLayout linearLayout = new LinearLayout(this); +linearLayout.setOrientation(LinearLayout.HORIZONTAL); + +linearLayout.addView(imageView); +singleLineComposer.setAuxiliaryButtonView(linearLayout); +``` + + + + +```kotlin +val imageView = ImageView(this) +imageView.setImageResource(R.drawable.save_icon) +val linearLayout = LinearLayout(this) +linearLayout.orientation = LinearLayout.HORIZONTAL + +linearLayout.addView(imageView) +singleLineComposer.setAuxiliaryButtonView(linearLayout) +``` + + + + + +*** + +#### setSendButtonView + +You can set a custom view in place of the already existing send button view using the following method. + + + +```java +singleLineComposer.setSendButtonView(view); +``` + + + + +```kotlin +singleLineComposer.setSendButtonView(view) +``` + + + + + +**Example** + + + + + +```xml drawable/custom_send_button.xml + + + + +``` + + + +```java +ImageView imageView = new ImageView(this); +imageView.setImageResource(R.drawable.custom_send_button); +imageView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Toast.makeText(YourActivity.this, "Custom Send Button Clicked !!!", Toast.LENGTH_SHORT).show(); + } +}); +singleLineComposer.setSendButtonView(imageView); +``` + + + + +```kotlin +val imageView = ImageView(this) +imageView.setImageResource(R.drawable.custom_send_button) +imageView.setOnClickListener { + Toast + .makeText(this@YourActivity, "Custom Send Button Clicked !!!", Toast.LENGTH_SHORT) + .show() +} +singleLineComposer.setSendButtonView(imageView) +``` + + + + + +*** + +#### setHeaderView + +You can set custom headerView to the SingleLineComposer component using the following method. + + + +```java +singleLineComposer.setHeaderView(view); +``` + + + + +```kotlin +singleLineComposer.setHeaderView(view) +``` + + + + + +**Example** + + + + + +In the following example, we're going to apply a mock smart reply view to the SingleLineComposer Component using the `.setHeaderView()` method. + +```xml custom_header_layout.xml + + + + + + + + + + + + + + +``` + + + +```java +View view = getLayoutInflater().inflate(R.layout.custom_header_layout, null); +singleLineComposer.setHeaderView(view); +``` + + + + +```kotlin +val view: View = LayoutInflater.from(context).inflate(R.layout.custom_header_layout, null) +singleLineComposer.setHeaderView(view) +``` + + + + + +*** + +#### setFooterView + +You can set a custom footer view to the SingleLineComposer component using the following method. + + + +```java +singleLineComposer.setFooterView(view); +``` + + + + +```kotlin +singleLineComposer.setFooterView(view) +``` + + + +