> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-feature-react-native-sdk-quotedmessage-a.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Message Composer

## Overview

MessageComposer is a [Component](/ui-kit/react-native/components-overview#components) that enables users to write and send a variety of messages, including text, image, video, and custom messages.

Features such as **Live Reaction**, **Attachments**, and **Message Editing** are also supported by it.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-feature-react-native-sdk-quotedmessage-a/1gtOmNl1ryouxO5Y/images/8becc772-message_composer-0cc03defaf535f332f7f8bb1ebd65392.png?fit=max&auto=format&n=1gtOmNl1ryouxO5Y&q=85&s=ee9e715ad3108aa8dbf6aa2f69dcd59f" width="2560" height="464" data-path="images/8becc772-message_composer-0cc03defaf535f332f7f8bb1ebd65392.png" />
</Frame>

## Usage

### Integration

The following code snippet illustrates how you can directly incorporate the `CometChatMessageComposer` component into your app.

<Tabs>
  <Tab title="App.tsx">
    ```tsx theme={null}
    import { CometChatMessageComposer } from "@cometchat/chat-uikit-react-native";
    //code
    return <CometChatMessageComposer group={group} />;
    ```
  </Tab>
</Tabs>

### Actions

[Actions](/ui-kit/react-native/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.

##### onSendButtonPress

The `onSendButtonPress` event gets activated when the send message button is clicked. It has a predefined function of sending messages entered in the composer `EditText`. However, you can overide this action with the following code snippet.

<Tabs>
  <Tab title="App.tsx">
    ```tsx theme={null}
    import { CometChatMessageComposer } from "@cometchat/chat-uikit-react-native";
    //code
    const onSendButtonPressHandler = (message: CometChat.BaseMessage) => {
      //code
    };
    return (
      <CometChatMessageComposer
        group={group}
        onSendButtonPress={onSendButtonPressHandler}
      />
    );
    ```
  </Tab>
</Tabs>

##### onError

This action doesn't change the behavior of the component but rather listens for any errors that occur in the `CometChatMessageComposer` component.

<Tabs>
  <Tab title="App.tsx">
    ```tsx theme={null}
    import { CometChatMessageComposer } from "@cometchat/chat-uikit-react-native";
    //code
    const onError = (error: CometChat.CometChatException) => {
      //handle error
    };
    return (
      <CometChatMessageComposer
        group={group}
        onError={onError}
      />
    );
    ```
  </Tab>
</Tabs>

##### onTextChange

Function triggered whenever the message input's text value changes, enabling dynamic text handling.

<Tabs>
  <Tab title="App.tsx">
    ```tsx theme={null}
    import { CometChatMessageComposer } from "@cometchat/chat-uikit-react-native";
    //code
    const onTextChange = (text: string) => {
      //code
    };
    return (
      <CometChatMessageComposer
        group={group}
        onTextChange={onTextChange}
      />
    );
    ```
  </Tab>
</Tabs>

***

### Filters

MessageComposer component does not have any available filters.

***

### Events

[Events](/ui-kit/react-native/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 list of events emitted by the Messages component is as follows.

| Event                     | Description                                                                                                                                       |
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| **ccMessageSent**         | Triggers whenever a loggedIn user sends any message, it will have two states such as: `inprogress`, `success` & `error`                           |
| **ccMessageEdited**       | Triggers whenever a loggedIn user edits any message from the list of messages. It will have two states such as: `inprogress`, `success` & `error` |
| **ccMessageLiveReaction** | Triggers whenever a loggedIn clicks on live reaction                                                                                              |

Adding `CometChatMessageEvents` Listener's

<Tabs>
  <Tab title="JavaScript">
    ```js theme={null}
    import { CometChatUIEventHandler } from "@cometchat/chat-uikit-react-native";

    CometChatUIEventHandler.addMessageListener("MESSAGE_LISTENER_ID", {
      ccMessageSent: (item) => {
        //code
      },
    });

    CometChatUIEventHandler.addMessageListener("MESSAGE_LISTENER_ID", {
      ccMessageEdited: (item) => {
        //code
      },
    });

    CometChatUIEventHandler.addMessageListener("MESSAGE_LISTENER_ID", {
      ccMessageLiveReaction: (item) => {
        //code
      },
    });
    ```
  </Tab>
</Tabs>

***

Removing `CometChatMessageEvents` Listener's

<Tabs>
  <Tab title="JavaScript">
    ```js theme={null}
    import { CometChatUIEventHandler } from "@cometchat/chat-uikit-react-native";

    CometChatUIEventHandler.removeMessageListener("MESSAGE_LISTENER_ID");
    ```
  </Tab>
</Tabs>

***

## Customization

To fit your app's design requirements, you can customize the appearance of the MessageComposer 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.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-feature-react-native-sdk-quotedmessage-a/o4nkL6PV5-93ajk5/images/482915e0-message_composer_styling-db627f8855f376a0287e9d2d7f0be603.png?fit=max&auto=format&n=o4nkL6PV5-93ajk5&q=85&s=617e47161bc83cfc5b6d636e0821761b" width="1280" height="232" data-path="images/482915e0-message_composer_styling-db627f8855f376a0287e9d2d7f0be603.png" />
</Frame>

***

### 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 show                                                                                                                                                                          | `user={chatUser}`                                                |
| **group**                             | Used to pass group object of which header specific details will be shown                                                                                                                                                                        | `group={chatGroup}`                                              |
| **disableTypingEvents**               | Used to disable/enable typing events , default false                                                                                                                                                                                            | `disableTypingEvents={true}`                                     |
| **disableSoundForOutgoingMessages**   | Used to toggle sound for outgoing messages                                                                                                                                                                                                      | `disableSoundForOutgoingMessages={true}`                         |
| **initialComposertext**               | Used to set predefined text                                                                                                                                                                                                                     | `initialComposertext="Your custom text"`                         |
| **customSoundForOutgoingMessage**     | Used to give custom sounds to outgoing messages                                                                                                                                                                                                 | `customSoundForOutgoingMessage="your custom sound for messages"` |
| **hideVoiceRecordingButton**          | used to hide the voice recording option.                                                                                                                                                                                                        | `hideVoiceRecording={true}`                                      |
| **hideCameraOption**                  | toggle visibility of camera option from the attachment options.                                                                                                                                                                                 | `hideCameraOption={true}`                                        |
| **hideImageAttachmentOption**         | toggle visibility of image attachment options.                                                                                                                                                                                                  | `hideImageAttachmentOption={true}`                               |
| **hideVideoAttachmentOption**         | toggle visibility of video attachment options.                                                                                                                                                                                                  | `hideVideoAttachmentOption={true}`                               |
| **hideAudioAttachmentOption**         | toggle visibility of audio attachment options.                                                                                                                                                                                                  | `hideAudioAttachmentOption={true}`                               |
| **hideFileAttachmentOption**          | toggle visibility of file attachment options.                                                                                                                                                                                                   | `hideFileAttachmentOption={true}`                                |
| **hidePollsAttachmentOption**         | toggle visibility of file polls attachment options.                                                                                                                                                                                             | `hidePollsAttachmentOption={true}`                               |
| **hideCollaborativeDocumentOption**   | toggle visibility of file Collaborative Document Option.                                                                                                                                                                                        | `hideCollaborativeDocumentOption={true}`                         |
| **hideCollaborativeWhiteboardOption** | toggle visibility of file Collaborative Whiteboard Option.                                                                                                                                                                                      | `hideCollaborativeWhiteboardOption={true}`                       |
| **hideAttachmentButton**              | toggle visibility of hide attachment option.                                                                                                                                                                                                    | `hideAttachmentButton={true}`                                    |
| **hideStickersButton**                | toggle visibility of hide stickers option.                                                                                                                                                                                                      | `hideStickersButton={true}`                                      |
| **hideSendButton**                    | toggle visibility of send button option.                                                                                                                                                                                                        | `hideSendButton={true}`                                          |
| **hideAuxiliaryButtons**              | toggle visibility of Auxiliary button option.                                                                                                                                                                                                   | `hideAuxiliaryButtons={true}`                                    |
| **disableMentions**                   | 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. | `disableMentions={true}`                                         |

***

### 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.

***

#### TextFormatters

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/react-native/mentions-formatter-guide)

<Tabs>
  <Tab title="App.tsx">
    ```tsx theme={null}
    import {
      CometChatMessageComposer,
      CometChatTextFormatter,
      CometChatMentionsFormatter,
    } from "@cometchat/chat-uikit-react-native";
    import { CometChat } from "@cometchat/chat-sdk-react-native";
    //code
    const getTextFomatters = () => {
      const textFormatters: CometChatTextFormatter[] = [];
      const mentionsFormatter = new CometChatMentionsFormatter();
      mentionsFormatter.setMentionsStyle({
        textStyle: {
          color: "#D6409F",
        },
        selfTextStyle: {
          color: "#30A46C",
        },
      });
      textFormatters.push(mentionsFormatter);
      return textFormatters;
    };
    return (
      <CometChatMessageComposer
        group={group}
        textFormatters={getTextFomatters()}
      />
    );
    ```
  </Tab>
</Tabs>

**Example**

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-feature-react-native-sdk-quotedmessage-a/-VkygUOl1ts-0wu1/images/b2f00911-mentions_message_composer-b1d1dd7961bc3c2953e7439bb516200b.png?fit=max&auto=format&n=-VkygUOl1ts-0wu1&q=85&s=459f62131e5e55a76ac3332ee79b4c20" width="1280" height="800" data-path="images/b2f00911-mentions_message_composer-b1d1dd7961bc3c2953e7439bb516200b.png" />
</Frame>

#### AttachmentOptions

By using `attachmentOptions`, you can set a list of custom `MessageComposerActions` for the MessageComposer Component. This will override the existing list of `MessageComposerActions`.

<Tabs>
  <Tab title="App.tsx">
    ```tsx theme={null}
    import {
      CometChatMessageComposer,
      CometChatTextFormatter,
      CometChatMentionsFormatter,
    } from "@cometchat/chat-uikit-react-native";
    import { CometChat } from "@cometchat/chat-sdk-react-native";
    //code
    const getCustomAttachmentOptions = ({
      user,
      group,
      composerId,
    }: {
      user?: CometChat.User;
      group?: CometChat.Group;
      composerId: Map<any, any>;
    }): CometChatMessageComposerAction[] => {
      let attachmentOptions: CometChatMessageComposerAction[] = [];
      attachmentOptions.push({
        id: "location",
        icon: LocationIcon,
        title: "Share Location",
        style: { iconStyle: { tintColor: "grey" } },
        onPress: () => {
          //handleOnPress
        },
      });
      return attachmentOptions;
    };
    return (
      <CometChatMessageComposer
        group={group}
        attachmentOptions={getCustomAttachmentOptions()}
      />
    );
    ```
  </Tab>
</Tabs>

**Example**

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-feature-react-native-sdk-quotedmessage-a/VUBQ7fIRG950PjPY/images/927b388b-message_composer_attachment_options-7fab1d4e46f7ec14b998d555d3d26968.png?fit=max&auto=format&n=VUBQ7fIRG950PjPY&q=85&s=95fb6572db1a7f34a8cc092fbdf733b6" width="1280" height="935" data-path="images/927b388b-message_composer_attachment_options-7fab1d4e46f7ec14b998d555d3d26968.png" />
</Frame>

***

#### AuxiliaryButtonView

You can insert a custom view into the MessageComposer component to add additional functionality using the following method.

<Tabs>
  <Tab title="App.tsx">
    ```tsx theme={null}
    import { CometChat } from "@cometchat/chat-sdk-react-native";
    import { CometChatMessageComposer } from "@cometchat/chat-uikit-react-native";
    //code

    const styles = StyleSheet.create({
      button: {
        height: 25,
        width: 25,
        borderRadius: 0,
        backgroundColor: "transparent",
      },
      image: {
        height: 23,
        width: 24,
        tintColor: "#7E57C2",
      },
    });

    const customAuxiliaryButtonView = ({
      user,
      group,
      composerId,
    }: {
      user?: CometChat.User,
      group?: CometChat.Group,
      composerId: string | number,
    }): JSX.Element => {
      return (
        <TouchableOpacity
          style={styles.button}
          onPress={() => {
            /* code */
          }}
        >
          <Image source={LocationIcon} style={styles.image} />
        </TouchableOpacity>
      );
    };

    return (
      <CometChatMessageComposer
        group={group}
        AuxiliaryButtonView={customAuxiliaryButtonView}
      />
    );
    ```
  </Tab>
</Tabs>

Please note that the MessageComposer Component utilizes the AuxiliaryButton to provide sticker functionality. Overriding the AuxiliaryButton will subsequently replace the sticker functionality.

**Example**

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-feature-react-native-sdk-quotedmessage-a/ZiXV5iCXIbI0bphk/images/673c7c47-message_composer_auxiliary_button_view-d7be5a9bcabce2d9260e8338658c8fc7.png?fit=max&auto=format&n=ZiXV5iCXIbI0bphk&q=85&s=3ee12abeb89cee56a3dbcecf5e1f39b0" width="1280" height="240" data-path="images/673c7c47-message_composer_auxiliary_button_view-d7be5a9bcabce2d9260e8338658c8fc7.png" />
</Frame>

***

#### SendButtonView

You can set a custom view in place of the already existing send button view. Using the following method.

<Tabs>
  <Tab title="App.tsx">
    ```tsx theme={null}
    import { CometChat } from "@cometchat/chat-sdk-react-native";
    import { CometChatMessageComposer } from "@cometchat/chat-uikit-react-native";
    //code
    const styles = StyleSheet.create({
      button: {
        height: 25,
        width: 25,
        borderRadius: 0,
        backgroundColor: "transparent",
      },
      image: {
        height: 23,
        width: 24,
        tintColor: "#7E57C2",
      },
    });

    const customSendButtonView = ({
      user,
      group,
      composerId,
    }: {
      user?: CometChat.User,
      group?: CometChat.Group,
      composerId: string | number,
    }): JSX.Element => {
      return (
        <TouchableOpacity
          style={styles.button}
          onPress={() => {
            /* code */
          }}
        >
          <Image source={SendButtonIcon} style={styles.image} />
        </TouchableOpacity>
      );
    };

    return (
      <CometChatMessageComposer
        group={group}
        SendButtonView={customSendButtonView}
      />
    );
    ```
  </Tab>
</Tabs>

**Example**

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-feature-react-native-sdk-quotedmessage-a/nV1KIvn8ZxahSHvn/images/3a7932a2-message_composer_send_button_view-f2e27a65301a5ced00e5854fa3b4ee6f.png?fit=max&auto=format&n=nV1KIvn8ZxahSHvn&q=85&s=90c5042311127f8292c141a02142ee7f" width="1280" height="240" data-path="images/3a7932a2-message_composer_send_button_view-f2e27a65301a5ced00e5854fa3b4ee6f.png" />
</Frame>

***

#### HeaderView

You can set custom headerView to the MessageComposer component using the following method

<Tabs>
  <Tab title="App.tsx">
    ```tsx theme={null}
    import { CometChat } from "@cometchat/chat-sdk-react-native";
    import { CometChatMessageComposer } from "@cometchat/chat-uikit-react-native";
    //code
    const viewStyle: StyleProp<ViewStyle> = {
      flexDirection: "row",
      alignItems: "flex-start",
      justifyContent: "center",
      padding: 5,
      borderColor: "black",
      borderWidth: 1,
      backgroundColor: "white",
      borderRadius: 10,
      margin: 2,
      marginLeft: 7.4,
      height: 30,
      width: "95.5%",
    };

    const customHeaderView = ({
      user,
      group,
    }: {
      user?: CometChat.User,
      group?: CometChat.Group,
    }) => {
      return (
        <View style={viewStyle}>
          <Text style={{ color: "#6851D6", fontWeight: "bold" }}>Chat Bot</Text>
        </View>
      );
    };

    return (
      <CometChatMessageComposer
        group={group}
        HeaderView={customHeaderView}
      />
    );
    ```
  </Tab>
</Tabs>

**Example**

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-feature-react-native-sdk-quotedmessage-a/_FWwfJpY0a1-Jsg7/images/dbb04a8b-message_composer_header_view-11ddf1d50aa74a8868351007037451f9.png?fit=max&auto=format&n=_FWwfJpY0a1-Jsg7&q=85&s=3cbe6cd07e37f81153071c016ccdcd5a" width="1280" height="240" data-path="images/dbb04a8b-message_composer_header_view-11ddf1d50aa74a8868351007037451f9.png" />
</Frame>
