> ## Documentation Index
> Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Emoji Keyboard

> A categorised emoji picker with a strip of category tabs, opened by the message list in a 400 pt sheet to add a reaction.

`CometChatEmojiKeyboard` is a categorised emoji picker: eight sections in one scrolling
grid, under a strip of category icons. The [message list](https://www.cometchat.com/docs/ui-kit/ios/v6/message-list.md)
opens it to add a reaction. You can also host it yourself.

The emojis come with the Kit — no extension and no network. There is no search, no recents
and no skin tones.

![CometChatEmojiKeyboard showing emoji categories and the Smileys set](https://mintcdn.com/cometchat-22654f5b/pWDsskjSUHgot30F/images/ui-kit/ios/v6/docs-overview-emoji-keyboard.png?fit=max\&auto=format\&n=pWDsskjSUHgot30F\&q=85\&s=c9241248ca89868bd4f070eb08be154d)

***

## Where It Fits

```
CometChatMessageList
   │ the message menu's add-reaction button,
   │ or the reactions row's "+" / "+N" chip
   ▼
┌───────────────────────────────┐
│ CometChatEmojiKeyboard ← here │   in a 400 pt sheet
└───────────────────────────────┘
   │ onClick(emoji)
   ▼
the list adds the reaction and closes the sheet
```

The message list opens the keyboard in a 400 pt sheet with a grabber, from both the message
menu's add-reaction button and the reactions row's "+" / "+N" chip. Picking an emoji
**adds** it as a reaction — picking one you have already reacted with sends it again rather
than removing it — and closes the sheet.

> [tab] SwiftUI
>
> `CometChatEmojiKeyboard` is a `View`. The emoji file is read once per app run, so after the
> first open the keyboard appears full.
>
> To show your own picker instead, set `onEmojiPickerClick` (the menu's button) or
> `onAddMoreReactionsClick` (the "+" chip) on the list; either replaces the keyboard for its
> entry. See [Message List ▸ Reactions](https://www.cometchat.com/docs/ui-kit/ios/v6/message-list.md#reactions).

> [tab] UIKit
>
> `CometChatEmojiKeyboard` is a `UIViewController`. It reads the emoji file in
> `viewDidLoad`; a keyboard never shown reads nothing.
>
> `set(onEmojiPickerClick:)` and `set(onAddMoreReactionsClick:)` on the list replace the
> keyboard with your own picker for their entry. The list's `emojiKeyboardStyle` styles every
> keyboard it presents. See [Message List](https://www.cometchat.com/docs/ui-kit/ios/v6/message-list.md).

***

## Quick Start

The keyboard does not close itself and does not add a reaction; the host does both.

> [tab] SwiftUI
>
> The keyboard fills the space it is given. In a sheet at the list's height:
>
> ```swift theme={null}
> struct ReactionPicker: View {
>     @State private var showing = false
>
>     var body: some View {
>         Button("React") { showing = true }
>             .sheet(isPresented: $showing) {
>                 CometChatEmojiKeyboard(onClick: { emoji in
>                     react(with: emoji)
>                     showing = false               // the keyboard does not close itself
>                 })
>                 .presentationDetents([.height(EmojiKeyboardMetrics.sheetHeight)])
>                 .presentationDragIndicator(.visible)
>             }
>     }
> }
> ```

> [tab] UIKit
>
> ```swift theme={null}
> final class ReactionsViewController: UIViewController {
>     func showEmojiKeyboard() {
>         let keyboard = CometChatEmojiKeyboard()
>         keyboard.setOnClick { [weak self] emoji in
>             print("picked", emoji.emoji)
>             self?.dismiss(animated: true)          // the keyboard does not close itself
>         }
>         keyboard.modalPresentationStyle = .pageSheet
>         if let sheet = keyboard.sheetPresentationController {
>             sheet.detents = [.custom { _ in 400 }]
>             sheet.prefersGrabberVisible = true
>         }
>         present(keyboard, animated: true)
>     }
> }
> ```

***

## Actions and Events

### Callback Methods

> [tab] SwiftUI
>
> | Parameter | Signature | When |
> | - | - | - |
> | `onClick` | `(String) -> Void` | an emoji is tapped |
> | `onLongClick` | `(String) -> Void` | an emoji is long-pressed |
>
> Both hand back the emoji as a `String`.

> [tab] UIKit
>
> | Setter | Signature | When |
> | - | - | - |
> | `setOnClick(onClick:)` | `(CometChatEmoji) -> Void` | an emoji is tapped |
> | `set(onLongClick:)` | `((CometChatEmoji) -> Void)?` | an emoji is long-pressed |
>
> `CometChatEmoji` carries the `emoji` and its `keywords`.

***

## How It Behaves

* **Scrolling selects a tab.** The selected tab is the *last* category with any part on
  screen.
* **Tapping a tab** scrolls that category's name to the top. A tap while the grid is still
  moving only highlights the tab.
* The strip keeps the selected tab in view.
* If the bundled file cannot be read, the keyboard stays blank. There is no error state.

> [tab] SwiftUI
>
> The tab moves on as soon as the next category's name scrolls into view at the bottom.
> Category names come from the emoji file and are not translated — "symbols" is lower-case
> there.

> [tab] UIKit
>
> The grid fills from the strip down to the bottom safe area.

***

## Functionality

> [tab] SwiftUI
>
> | Parameter | Type | Default |
> | - | - | - |
> | `store` | `CometChatEmojiKeyboardStore?` | `nil` |
> | `style` | `CometChatEmojiKeyboardStyle` | |
> | `onClick` | `(String) -> Void` | |
> | `onLongClick` | `(String) -> Void` | |

> [tab] UIKit
>
> | Member | Purpose |
> | - | - |
> | `style` | an `EmojiKeyboardStyle`. `CometChatEmojiKeyboard.style` is the default every new keyboard copies |
> | `emojiCategories` | the categories, readable |
> | `selectedEmojiSetCategoryIndex` | the selected tab, readable |
> | `emojiCollectionView`, `emojiSetCollectionView` | the grid and the strip, readable |

***

## Advanced Methods

### Store Access

> [tab] SwiftUI
>
> `CometChatEmojiKeyboardStore` reads the emoji file and holds the categories and the
> selected tab. Pass a seeded one to show fixed emojis — in a preview, for example. A seeded
> store never reads the file:
>
> ```swift theme={null}
> #Preview {
>     let faces = ChatEmojiCategory(id: "people", name: "Smileys",
>                                   emojis: ["😀", "😂", "😍"].map { ChatEmoji(emoji: $0) })
>     CometChatEmojiKeyboard(store: CometChatEmojiKeyboardStore(seeded: .content, categories: [faces]))
>         .frame(height: 400)
> }
> ```
>
> To supply another emoji set, implement `EmojiRepository` and pass it:
> `CometChatEmojiKeyboardStore(repository: MyEmojiSet())`.

> [tab] UIKit
>
> The keyboard reads its own emoji set. Read the categories with `emojiCategories`.

### Subclassing

> [tab] SwiftUI
>
> `CometChatEmojiKeyboard` is a `View` struct. Customise it with its parameters and style.

> [tab] UIKit
>
> Override `setupUI()`, `setupCollectionView()` or `setupStyle()` and call `super`. The
> collection views are `emojiCollectionView` (the grid) and `emojiSetCollectionView` (the
> strip), and the data-source methods are `open`:
>
> ```swift theme={null}
> final class TallTabsKeyboard: CometChatEmojiKeyboard {
>     override func setupStyle() {
>         super.setupStyle()
>         emojiSetCollectionView.backgroundColor = .secondarySystemBackground
>     }
> }
> ```

***

## Accessibility

> [tab] SwiftUI
>
> * Each emoji is a button that reads as the emoji. Each tab is a button that reads as the
>   category's name, marked selected for the current one; each section name is a heading.
> * Section names follow Dynamic Type and never truncate; the emojis stay 30 pt.

> [tab] UIKit
>
> * Each emoji is a button that reads as the emoji; each tab a button named after its
>   category, marked selected for the current one; each section name a heading.

***

## Style

> [tab] SwiftUI
>
> `CometChatEmojiKeyboardStyle` is sparse: set only what you change, and everything else
> follows the theme.
>
> | Property | Default |
> | - | - |
> | `backgroundColor` | `background1` |
> | `cornerRadius` | 0 — a sheet rounds the keyboard |
> | `strokeWidth`, `strokeColor` | 0, `strokeLight` — the border adds no padding |
> | `separatorColor` | `nil` — no line between the strip and the grid; a colour draws a 1 pt line |
> | `categoryTextColor`, `categoryTextStyle` | `textSecondary`, `bodyRegular` — the section names |
> | `categoryIconTint`, `selectedCategoryIconTint` | `iconTintSecondary`, `iconTintHighlight` |
> | `tabIconSize` | 24 — the tab icon's height |
>
> ```swift theme={null}
> var style = CometChatEmojiKeyboardStyle()
> style.selectedCategoryIconTint = .orange
> style.separatorColor = .gray.opacity(0.3)
>
> CometChatEmojiKeyboard(style: style, onClick: { react(with: $0) })
> ```
>
> The message list does not pass a style to the keyboard it presents.

> [tab] UIKit
>
> `EmojiKeyboardStyle` is the style type. Unset fields follow `CometChatUIKitTheme`.
>
> | Property | Default |
> | - | - |
> | `background` | `background1` |
> | `sectionHeaderFont`, `sectionHeaderColor` | `bodyRegular`, `textSecondary` |
> | `categoryIconTint`, `selectedCategoryIconTint` | `iconTintSecondary`, `iconTintHighlight` |
> | `cornerRadius`, `borderWidth`, `borderColor` | 0, 0, `strokeLight` |
> | `titleColor`, `titleFont`, `cancelButtonTint` | no effect — the keyboard has no title bar |
>
> There is no separator between the strip and the grid.
>
> ```swift theme={null}
> let style = EmojiKeyboardStyle()
> style.selectedCategoryIconTint = .systemOrange
> style.sectionHeaderFont = .preferredFont(forTextStyle: .footnote)
> CometChatEmojiKeyboard.style = style            // every keyboard created afterwards
>
> let keyboard = CometChatEmojiKeyboard()
> keyboard.style.background = .secondarySystemBackground   // this one only
> ```

***

## Next Steps

> [card] [Message List](https://www.cometchat.com/docs/ui-kit/ios/v6/message-list.md)
>
> Opens the keyboard to add a reaction

> [card] [Message Composer](https://www.cometchat.com/docs/ui-kit/ios/v6/message-composer.md)
>
> Compose and send messages


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.