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

# Sticker Keyboard

> Sticker sets from the Stickers extension in a paged grid with a tab bar, hosted by the message composer or by your own screen.

`CometChatStickerKeyboard` shows your app's stickers: one page per sticker set, a grid of
four columns, and a tab bar of set icons at the bottom. It fetches the sets itself and
reports the sticker a user taps; the host sends it. The
[message composer](https://www.cometchat.com/docs/ui-kit/ios/v6/message-composer.md) opens it from its sticker button and
sends the sticker you tap. You can also host it yourself.

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

***

## Where It Fits

> [tab] SwiftUI
>
> ```
> CometChatMessageComposer
>         │ sticker button
>         ▼
> ┌─────────────────────────────────┐
> │ CometChatStickerKeyboard ← here │   in place of the system keyboard
> └─────────────────────────────────┘
>         │ onStickerClick(sticker)
>         ▼
>    the composer sends the sticker
> ```
>
> `CometChatStickerKeyboard` is a `View`. It fetches the sticker sets when it first appears.
>
> The composer's sticker button opens it, as tall as the system keyboard was — at least
> 296 pt. Tapping a sticker sends it, and the keyboard stays open. The sticker button or a
> tap in the text field closes it. See
> [Message Composer ▸ Stickers](https://www.cometchat.com/docs/ui-kit/ios/v6/message-composer.md#stickers).

> [tab] UIKit
>
> The [message composer](https://www.cometchat.com/docs/ui-kit/ios/v6/message-composer.md) hosts it: its sticker button opens
> the keyboard under the input at 296 pt, sends a tapped sticker, and calls
> `set(onStickerSelected:)`. Through the composer you only style it:
>
> ```swift theme={null}
> let style = StickerKeyboardStyle()
> style.separatorColor = .systemIndigo
> composer.set(stickerKeyboardStyle: style)
> ```
>
> Use the keyboard directly only in a screen of your own. `CometChatStickerKeyboard` is a
> `UIView`.

Stickers come from the **Stickers** extension, which must be enabled on your CometChat
dashboard.

***

## Quick Start

> [tab] SwiftUI
>
> Give it a height, and handle the tap. The keyboard does not close itself:
>
> ```swift theme={null}
> CometChatStickerKeyboard(onStickerClick: { sticker in log(sticker.name) })
>     .frame(height: 296)
> ```
>
> To send the sticker to a chat, use a composer store:
>
> ```swift theme={null}
> struct MyStickerPanel: View {
>     let composer: MessageComposerStore
>
>     var body: some View {
>         CometChatStickerKeyboard(onStickerClick: { sticker in
>             composer.sendStickerMessage(stickerUrl: sticker.url, stickerName: sticker.name,
>                                         pushNotificationMessage: "Shared a Sticker")
>         })
>         .frame(height: 296)
>     }
> }
> ```
>
> With the Stickers extension turned off, `onError` receives `ERR_EXTENSION_NOT_ENABLED`.

> [tab] UIKit
>
> Add it at the bottom of a screen and send what is tapped. It sizes its own height from its
> grid; give it none.
>
> ```swift theme={null}
> final class StickerPickerViewController: UIViewController {
>     private let store = MessageComposerStore()
>     private let keyboard = CometChatStickerKeyboard()
>
>     func show(for user: CometChatSDK.User) {
>         store.setUser(user)
>         keyboard.setOnStickerTap { [weak self] sticker in
>             self?.store.sendStickerMessage(stickerUrl: sticker.url, stickerName: sticker.name,
>                                            pushNotificationMessage: "Shared a sticker")
>         }
>         .set(onError: { error in log(error) })
>
>         keyboard.translatesAutoresizingMaskIntoConstraints = false
>         view.addSubview(keyboard)
>         NSLayoutConstraint.activate([
>             keyboard.leadingAnchor.constraint(equalTo: view.leadingAnchor),
>             keyboard.trailingAnchor.constraint(equalTo: view.trailingAnchor),
>             keyboard.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
>         ])
>     }
> }
> ```
>
> The keyboard fetches the first time it moves into a window, never earlier; moving it to
> another window keeps what it fetched. A tap does not close it.
>
> > [!NOTE]
> >
> > With the Stickers extension disabled for your app, the keyboard shows its error state
> > and `onError` receives `ERR_EXTENSION_NOT_ENABLED`.

***

## What It Shows

> [tab] SwiftUI
>
> | State | Shows | Hide with |
> | - | - | - |
> | loading | a shimmer of cells and tabs | `hideLoadingState` |
> | content | the sets | — |
> | empty | a sticker icon, "No Stickers Available" and "You don't have any stickers yet." | `hideEmptyState` |
> | error | "Looks like something went wrong. Please try again." and **Retry** | `hideErrorState` |
>
> ![The sticker keyboard showing content: a four-column grid of the selected set's stickers over a separator, and the tab bar of set icons](https://mintcdn.com/cometchat-22654f5b/pWDsskjSUHgot30F/images/ui-kit/ios/v6/docs-stickers.png?fit=max\&auto=format\&n=pWDsskjSUHgot30F\&q=85\&s=9b2156b7c6667c3880e52e7a67f39cda)
>
> The texts can be replaced with `emptyStateTitleText`, `emptyStateSubtitleText` and
> `errorStateText`. A hidden state renders nothing.
>
> Sets appear in the order the extension returns them — the app's default stickers first,
> then custom ones. A set's tab icon is its first sticker. A sticker that fails to load
> shows a placeholder sticker. An animated GIF sticker shows its first frame in the
> keyboard; what is sent is the GIF's URL.
>
> `onError` is called every time the keyboard enters the error state, and when it appears
> already in it.

> [tab] UIKit
>
> | State | Shows |
> | - | - |
> | loading | a shimmer of 16 cells in 4 columns |
> | content | one page per set, a 4-column grid each; a separator; the tab bar of set icons (no mark on the selected one) |
> | empty | a sticker icon, "No Stickers Available" and "You don't have any stickers yet." |
> | error | "Looks like something went wrong. Please try again." and a **Retry** button |
>
> Sets appear in the order the extension first lists them — the default sets, then your
> custom ones; the extension's set order is not used. A set's tab icon is its first sticker.
> Tapping a tab pages to its set, and swiping pages selects its tab; the tab bar does not
> scroll the selected tab into view. GIF stickers animate. A sticker whose image fails to
> load is retried once, then shows a placeholder sticker.
>
> The grid is 210 pt tall on phones up to 667 pt high and 250 pt otherwise, over a 49 pt tab
> bar.

`Sticker` carries `name`, `url` and `setName`, and `isGif` when the URL ends in `.gif`.

***

## Actions and Events

### Callback Methods

> [tab] SwiftUI
>
> | Parameter | Signature | When |
> | - | - | - |
> | `onStickerClick` | `(Sticker) -> Void` | a sticker is tapped |
> | `onError` | `(CometChatError) -> Void` | the keyboard enters its error state |

> [tab] UIKit
>
> | Setter | Signature | Called |
> | - | - | - |
> | `setOnStickerTap(onStickerTap:)` | `(Sticker) -> Void` | a sticker was tapped |
> | `set(onError:)` | `(CometChatException) -> Void` | every time the keyboard enters its error state |

***

## Functionality

> [tab] SwiftUI
>
> | Parameter | Type | Default |
> | - | - | - |
> | `store` | `CometChatStickerKeyboardStore?` | `nil` |
> | `style` | `CometChatStickerKeyboardStyle` | |
> | `hideLoadingState` | `Bool` | `false` |
> | `hideEmptyState` | `Bool` | `false` |
> | `hideErrorState` | `Bool` | `false` |
> | `emptyStateTitleText` | `String?` | `nil` |
> | `emptyStateSubtitleText` | `String?` | `nil` |
> | `errorStateText` | `String?` | `nil` |
> | `imageSource` | `any ImageSource` | |
>
> `loadingView`, `emptyView` and `errorView` replace the states — see Custom View Slots.

> [tab] UIKit
>
> | Setter | Type |
> | - | - |
> | `set(loadingStateView:)` | `UIView?` |
> | `set(emptyStateView:)` | `UIView?` |
> | `set(errorStateView:)` | `UIView?` |
> | `set(emptyStateTitleText:)` | `String` |
> | `set(emptyStateSubtitleText:)` | `String` |
> | `set(errorStateText:)` | `String` |
>
> `style` is a `StickerKeyboardStyle`. `CometChatStickerKeyboard.style` is the default every
> new keyboard copies.

***

## Custom View Slots

> [tab] SwiftUI
>
> Replace the loading, empty and error states. The error view receives a retry action:
>
> ```swift theme={null}
> CometChatStickerKeyboard(
>     loadingView: { AnyView(MyStickerSpinner()) },
>     emptyView: { AnyView(NoStickersYet()) },
>     errorView: { onRetry in AnyView(Button("Try again", action: onRetry)) }
> )
> ```
>
> Or for every sticker keyboard in a subtree, including the composer's. An initialiser
> argument wins:
>
> ```swift theme={null}
> MyAppRoot()
>     .cometChatStickerKeyboardEmptyView { NoStickersYet() }
>     .cometChatStickerKeyboardErrorView { onRetry in Button("Try again", action: onRetry) }
> ```

> [tab] UIKit
>
> ```swift theme={null}
> let keyboard = CometChatStickerKeyboard()
> keyboard
>     .set(loadingStateView: MyStickerSpinner())
>     .set(emptyStateView: NoStickersView())
>     .set(emptyStateTitleText: "No stickers yet")
>     .set(emptyStateSubtitleText: "Ask your admin to add a sticker pack.")
>     .set(errorStateText: "Stickers are unavailable right now.")
> ```
>
> A custom view is centred in the keyboard. It takes effect the **next** time its state is
> entered — setting one while that state is showing changes nothing. A custom error view is
> given no retry hook, and nothing public can retry, so it can never recover. Keep the
> built-in error state if users should be able to retry.

***

## Advanced Methods

### Store Access

> [tab] SwiftUI
>
> `CometChatStickerKeyboardStore` fetches and holds the sets. Pass your own to share it, to
> keep the fetched stickers when the keyboard goes away, or to show fixed stickers in a
> preview:
>
> ```swift theme={null}
> #Preview {
>     let set = StickerSet(name: "Cats", stickers: [
>         Sticker(name: "wave", url: "https://example.com/wave.png", setName: "Cats")
>     ])
>     CometChatStickerKeyboard(store: CometChatStickerKeyboardStore(seeded: .content, stickerSets: [set]))
>         .frame(height: 296)
> }
> ```
>
> A seeded store never fetches. The store also has `retry()`, `selectStickerSet(_:)`, and
> the observable `uiState`, `stickerSets`, `selectedSetIndex` and `currentStickers`.
>
> > [!WARNING]
> >
> > The keyboard sets the store's `onStickerClick` to its own `onStickerClick` when it
> > appears — **even when that is `nil`** — so a handler you set on an injected store is
> > replaced. Pass the handler to the keyboard instead.

> [tab] UIKit
>
> The keyboard creates its own store. To share one, host the keyboard through the composer.

### Subclassing

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

> [tab] UIKit
>
> | Method | Called |
> | - | - |
> | `buildUI()` | once, to build the view tree and its constraints |
> | `setupStyle()` | at creation, and when `style` is assigned |
>
> ```swift theme={null}
> final class RoundedStickerKeyboard: CometChatStickerKeyboard {
>     override func setupStyle() {
>         super.setupStyle()
>         layer.cornerRadius = 16
>         layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
>         clipsToBounds = true
>     }
> }
> ```
>
> These views are public for finer changes: `stickersCollectionView` (the pager),
> `stickerSetCollectionView` (the tab bar), `separatorLineView`, `emptyView`,
> `emptyImageView`, `emptyTitleLabel`, `emptySubTitleLabel`, `errorView`, `errorLabel`,
> `errorRetryButton` and `loadingView`. The custom views you set are readable as
> `customLoadingView`, `customEmptyView` and `customErrorView`.

### Objective-C

In the UIKit toolkit:

The keyboard is `@objc`, apart from `setOnStickerTap(onStickerTap:)`, whose `Sticker` is a
Swift struct — from Objective-C, host it through the composer. Swift's
`set(emptyStateTitleText:)` is `setWithEmptyStateTitleText:`; `set(onError:)` keeps
`setOnError:`:

```objc theme={null}
CometChatStickerKeyboard *keyboard = [[CometChatStickerKeyboard alloc] init];
[keyboard setWithEmptyStateTitleText:@"No stickers yet"];
[keyboard setOnError:^(CometChatException *error) { NSLog(@"%@", error.errorCode); }];

StickerKeyboardStyle *style = [[StickerKeyboardStyle alloc] init];
style.separatorColor = UIColor.systemIndigoColor;
keyboard.style = style;
```

***

## Accessibility

In the SwiftUI toolkit:

* Each sticker is a button that reads as its name, or "Sticker" when it has none. Each
  tab is a button that reads as "*name* sticker set", marked selected for the set shown.
* The loading state reads as "Loading stickers, please wait".
* Under Reduce Motion, the composer fades the keyboard in and out instead of sliding it.

***

## Style

> [tab] SwiftUI
>
> `CometChatStickerKeyboardStyle` is sparse: set only what you change, and everything else
> follows the theme. The composer passes its `stickerKeyboardStyle` through:
>
> ```swift theme={null}
> var stickers = CometChatStickerKeyboardStyle()
> stickers.backgroundColor = .black
> stickers.separatorColor = .yellow
>
> CometChatMessageComposer(user: user, stickerKeyboardStyle: stickers)
> ```
>
> | Property | Default |
> | - | - |
> | `backgroundColor` | `background1` |
> | `separatorColor` | `strokeDefault` — the line above the tab bar |
> | `tabIconSize` | 32 |
> | `stickerItemSize` | `nil` — four cells fill the width; a value fixes the cell size |
> | `emptyStateTitleTextColor`, `emptyStateTitleTextStyle` | `textPrimary`, `heading4Medium` |
> | `emptyStateSubtitleTextColor`, `emptyStateSubtitleTextStyle` | `textSecondary`, `bodyRegular` |
> | `errorStateTextColor`, `errorStateTextStyle` | `textSecondary`, `bodyRegular` |

> [tab] UIKit
>
> The static style is the default every keyboard created **afterwards** copies:
>
> ```swift theme={null}
> CometChatStickerKeyboard.style.backgroundColor = .secondarySystemBackground
> CometChatStickerKeyboard.style.separatorColor = .systemIndigo
> ```
>
> To style one keyboard, assign a style. Assigning `style` applies it.
>
> ```swift theme={null}
> let style = StickerKeyboardStyle()
> style.separatorColor = .separator
> style.emptyStateTitleTextFont = .preferredFont(forTextStyle: .headline)
>
> let keyboard = CometChatStickerKeyboard()
> keyboard.style = style
> ```
>
> Unset properties follow `CometChatUIKitTheme`.
>
> | Property | Default |
> | - | - |
> | `backgroundColor` | `background1` |
> | `separatorColor` | `strokeDefault` — the line above the tab bar |
> | `emptyStateTitleTextColor`, `emptyStateTitleTextFont` | `textPrimary`, `heading4Medium` |
> | `emptyStateSubtitleTextColor`, `emptyStateSubtitleTextFont` | `textSecondary`, `bodyRegular` |
> | `errorStateTextColor`, `errorStateTextFont` | `textSecondary`, `bodyRegular` |
>
> `tabIconSize` and `stickerItemSize` have no effect: tab icons are 32 pt and cells a quarter
> of the width.

***

## Next Steps

> [card] [Message Composer](https://www.cometchat.com/docs/ui-kit/ios/v6/message-composer.md)
>
> Hosts the keyboard behind its sticker button

> [card] [Create Poll](https://www.cometchat.com/docs/ui-kit/ios/v6/create-poll.md)
>
> The composer's other hosted component


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