# React Native Messenger and team chat UI (Pro)

> React Native chat between people for iOS, Android and the web, at WhatsApp and Slack depth: an inbox, a thread with replies, reactions, read receipts, albums, files, links, polls, voice recording, edit, delete, forward, pins, search and select, a details panel, and a Slack-style channel with threads. Part of Patine Pro, React Native core only.

# Messenger Pro

The parts of a chat between people, as WhatsApp, iMessage, Telegram and Slack build them.

- `ConversationList` is the inbox: pinned first, presence, who's typing, drafts, the last message with read ticks, unread counts, and swipe actions.
- `MessengerThread` is the conversation: day headings, a **New messages** line, quoted replies that jump to the original, albums, videos, files, links, places, contacts, polls, voice messages, stickers, light formatting and @mentions, reactions, read ticks, and a long-press menu to react, reply, forward, copy, edit, pin, star, select, see who read it, or delete.
- `MessengerComposer` is its message box, on its own: attachments, emoji, @mentions, a reply or edit bar, and hold-to-record voice messages.
- `ChatDetails` is the panel about a conversation: its people, starred messages, and its media, files and links.
- `ChannelThread` is a Slack-style channel: plain rows, reaction chips and threads.

For an assistant that streams replies, use [AI Chat](./ai-chat). `MessengerScreen` and [`TeamChatScreen`](../pro/team-chat) put the parts together with demo people, ready to rename.

```tsx
import { ChannelThread, ChatDetails, ConversationList, MessengerComposer, MessengerThread, MessengerScreen } from '@patine-ui/pro';
```

```tsx live device
import { MessengerScreen } from '@patine-ui/pro';

export default function Example() {
  return <MessengerScreen />;
}
```

## Example: a team thread

A design team's group chat: names beside others' messages, a reply quoted in its bubble, reactions, read receipts on your own, and your messages added as you send them. Long-press a message (or hover it on the web) for its menu.

```tsx live
import { useState } from 'react';
import { View } from 'react-native';
import { MessengerThread, toggleReaction } from '@patine-ui/pro';

const NOW = Date.now();
const min = (n: number) => NOW - n * 60000;
const USERS = {
  me: { id: 'me', name: 'Omer' },
  maya: { id: 'maya', name: 'Maya Lindqvist', online: true },
  leo: { id: 'leo', name: 'Leo Brandt' },
};
const FIRST = [
  { id: '1', senderId: 'maya', text: 'Checkout v2 mocks are in Figma: *Payments / Review*', createdAt: min(42) },
  { id: '2', senderId: 'leo', text: 'Looks great. Can the promo code field collapse by default?', createdAt: min(38) },
  { id: '3', senderId: 'maya', text: 'Yes, behind “Add a code”. Updated.', createdAt: min(31), replyTo: '2', reactions: [{ emoji: '👍', userIds: ['leo'] }] },
  { id: '4', senderId: 'me', text: 'Shipping it to the 10% test group on Monday. @Maya can you post the link?', createdAt: min(12), status: 'read' as const },
];

export default function Example() {
  const [messages, setMessages] = useState(FIRST);
  const send = (text: string, { replyTo }: { replyTo?: string }) =>
    setMessages((all) => [...all, { id: String(Date.now()), senderId: 'me', text, replyTo, createdAt: Date.now(), status: 'sent' as const }]);
  const react = (id: string, emoji: string) =>
    setMessages((all) => all.map((m) => (m.id === id ? { ...m, reactions: toggleReaction(m.reactions, emoji, 'me') } : m)));
  const edit = (id: string, text: string) => setMessages((all) => all.map((m) => (m.id === id ? { ...m, text, edited: true } : m)));
  return (
    <View style={{ height: 520, width: '100%', maxWidth: 420 }}>
      <MessengerThread messages={messages} users={USERS} me="me" group typing={['Leo']} onSend={send} onReact={react} onEdit={edit} />
    </View>
  );
}
```

## The thread

`MessengerThread` is controlled: pass the messages, the people by id and your own id, and handle `onSend`. It tells you what the new message replies to, and which files go with it. Each handler you pass adds its action: `onEdit` adds Edit, `onDelete` adds Delete (for everyone on your own messages, for you on any), `onForward` with `forwardTargets` adds Forward, `onPin` and `onStar` add Pin and Star.

```tsx
<MessengerThread
  messages={messages}
  users={users}
  me="me"
  group
  lastReadAt={lastReadAt}
  typing={['Maya']}
  onSend={(text, { replyTo, attachments }) => api.send({ text, replyTo, attachments })}
  onReact={(id, emoji) => api.react(id, emoji)}
  onEdit={(id, text) => api.edit(id, text)}
  onDelete={(ids, forEveryone) => api.remove(ids, forEveryone)}
  forwardTargets={chats}
  onForward={(ids, chatIds) => api.forward(ids, chatIds)}
  pinnedIds={pinnedIds}
  onPin={api.togglePin}
  onStar={api.toggleStar}
  onCopy={Clipboard.setStringAsync}
/>
```

A message is `{ id, senderId, text?, createdAt, status?, replyTo?, reactions?, attachments?, voice?, link?, location?, contact?, poll?, sticker?, edited?, deleted?, forwarded?, starred?, readBy?, deliveredTo?, system? }`.

- **Ticks.** Your own messages show `status`: a clock while `sending`, one tick `sent`, two `delivered`, two in blue `read`. Each step pops in. Info lists `readBy` and `deliveredTo` with their times.
- **Formatting.** `text` takes `*bold*`, `_italic_`, `~strike~`, `` `code` ``, code blocks, links and `@mentions` of people in `users`; a mention of you is tinted. A few emoji alone draw large.
- **Replies.** `replyTo` draws the quoted message; tap it to jump there and flash it. Swipe a message to reply.
- **Deleted.** `deleted` draws "This message was deleted".
- **System lines.** `system` messages are a line in the middle ("Maya added Ana").

## Photos, files and cards

`attachments` group by kind. Photos and videos make an album (two side by side, three as one large and two small, four or more as a grid with "+N"), videos show their length, and a tap opens the viewer. Other files are cards with their type, size, upload `progress` and Download. `link` draws a preview card, `location` a map (live with `liveUntil`), `contact` a card with Message and Save, and `poll` a poll to vote in with animated results.

## Voice messages

Hold the mic to record, slide left to cancel, slide up to lock and let go. `onRecordStart` and `onRecordEnd` start and stop your recorder (for example `expo-audio`), `amplitude` (0 to 1) draws the live waveform, and `onSendVoice` gets `{ durationMs, waveform }`. A message with `voice: { durationMs, waveform? }` draws a play button and its waveform; `onPlayVoice` gets the message, and `playing` says which one plays.

## Search, pins and select

The search bar (`searchOpen`, `onSearchOpenChange`) marks matches, steps through them with up and down, and jumps to a date; tap a day heading to jump too. Pinned messages ride a bar at the top that cycles through them. Select from the menu ticks messages to star, copy, forward or delete together. Scrolled up, a button jumps back to the latest with how many arrived. `onLoadOlder`, `hasOlder` and `loadingOlder` page in older messages with a spinner.

## The composer

`MessengerThread` brings its own; use `MessengerComposer` alone under your own list. `variant="pill"` is a rounded field with a send button that turns into the mic, as phones do; `variant="box"` is a bordered box with a toolbar, as Slack does. Type `@` for a list of people to mention (arrow keys and Enter on the web).

```tsx
<MessengerComposer
  value={draft}
  onValueChange={setDraft}
  onSend={send}
  users={users}
  me="me"
  context={replyTo ? { kind: 'reply', title: `Replying to ${replyTo.name}`, text: replyTo.text, onCancel: clearReply } : undefined}
  onAttach={(kind) => pick(kind)}
  onSendVoice={sendVoice}
/>
```

## The details panel

`ChatDetails` shows a conversation's picture and name, call and search shortcuts, a mute switch, starred messages, Media, Files and Links tabs built from its messages, and its members with presence.

```tsx
<ChatDetails title="Lisbon crew" group participants={people} messages={messages} me="me" muted={muted} onMutedChange={setMuted} onSearch={openSearch} />
```

## The inbox

```tsx
<ConversationList
  conversations={conversations}
  me="me"
  users={users}
  active={openId}
  onSelect={open}
  onPin={togglePin}
  onMute={toggleMute}
  onArchive={archive}
  header={<SearchField value={query} onValueChange={setQuery} />}
/>
```

A conversation is `{ id, title, avatar?, group?, online?, lastMessage?, unread?, muted?, pinned?, typing?, draft? }`. A muted one's count is grey, and `draft` shows as "Draft: …". Swipe actions show only for the handlers you pass.

## Team chat

`ChannelThread` draws a channel as Slack does: no bubbles, the avatar and name heading each run, reactions as chips that toggle yours, and a message's `thread: { count, userIds, lastReplyAt }` as faces and a reply count that call `onOpenThread`. Hover a message on the web for three quick reactions, Reply in thread and its menu. For the thread's panel, pass the parent and its replies with `plain`.

```tsx live
import { useState } from 'react';
import { View } from 'react-native';
import { ChannelThread, toggleReaction } from '@patine-ui/pro';

const NOW = Date.now();
const USERS = {
  me: { id: 'me', name: 'Omer Katz' },
  sam: { id: 'sam', name: 'Sam Okafor' },
  leo: { id: 'leo', name: 'Leo Brandt' },
};
const FIRST = [
  {
    id: '1',
    senderId: 'sam',
    text: 'Rollout plan: *10%* on Dec 2, 50% on Dec 4, everyone Dec 6',
    createdAt: NOW - 50 * 60000,
    reactions: [{ emoji: '✅', userIds: ['leo'] }],
    thread: { count: 2, userIds: ['leo', 'me'], lastReplyAt: NOW - 20 * 60000 },
  },
  { id: '2', senderId: 'sam', text: '@Omer release notes by Monday?', createdAt: NOW - 49 * 60000 },
];

export default function Example() {
  const [messages, setMessages] = useState(FIRST);
  const react = (id: string, emoji: string) =>
    setMessages((all) => all.map((m) => (m.id === id ? { ...m, reactions: toggleReaction(m.reactions, emoji, 'me') } : m)));
  const send = (text: string) => setMessages((all) => [...all, { id: String(Date.now()), senderId: 'me', text, createdAt: Date.now() }]);
  return (
    <View style={{ height: 420, width: '100%' }}>
      <ChannelThread messages={messages} users={USERS} me="me" onSend={send} onReact={react} onOpenThread={() => {}} placeholder="Message #launch" />
    </View>
  );
}
```

## Accessibility

- Each message reads as one line: who, what, when, edited, starred and its receipt, with an action to open its menu.
- The menu has the menu role; reactions are buttons with who reacted, and Slack's chips are toggle buttons.
- Day headings are headings, and the composer says what you're replying to or editing, with a labelled Cancel.
- Swipe to reply and hover actions are shortcuts: everything is also in the long-press menu. Screen readers start a voice message locked, with Send and Discard on screen.
- Escape closes the menu, select mode and search on the web.

## Props

### MessengerThread

| Prop | Type | Default |
| --- | --- | --- |
| `messages` | `MessengerMessage[]`, oldest first | |
| `users` | `Record<id, { id, name, avatar?, online?, role? }>` | |
| `me` | `string`, your user id | |
| `group` | `boolean`: names and avatars beside others' messages | `false` |
| `lastReadAt` | `number`: the New messages line goes after it | |
| `typing` | `string[]`, names | `[]` |
| `onSend` | `(text, { replyTo?, attachments }) => void` | |
| `onReact` | `(messageId, emoji) => void` | |
| `onEdit`, `editWindowMs` | `(messageId, text) => void`, `number` | no limit |
| `onDelete` | `(messageIds, forEveryone) => void` | |
| `onForward`, `forwardTargets` | `(messageIds, targetIds) => void`, `{ id, title, avatar?, subtitle? }[]` | |
| `onPin`, `pinnedIds` | `(messageId) => void`, `string[]` | |
| `onStar` | `(messageIds) => void` | |
| `onCopy` | `(text) => void`: adds Copy | |
| `onAttach`, `attachKinds` | `(kind) => files \| undefined`, `('photo' \| 'camera' \| 'document' \| 'location' \| 'contact')[]` | |
| `onSendPoll` | `(poll) => void`: adds Poll to + | |
| `onVote` | `(messageId, optionIds) => void` | |
| `onSendVoice`, `onRecordStart`, `onRecordEnd`, `amplitude` | voice recording | |
| `onPlayVoice`, `playing` | `(message) => void`, `string` | |
| `onOpenLink`, `onOpenAttachment`, `onDownload`, `onOpenLocation`, `onContactAction` | open what a message carries | |
| `onLoadOlder`, `hasOlder`, `loadingOlder` | `() => void`, `boolean`, `boolean` | |
| `searchOpen`, `onSearchOpenChange` | `boolean`, `(open) => void` | |
| `banner` | `ReactNode`, over the messages | |
| `labels` | `Partial<MessengerLabels>` | English |

### ChannelThread

The thread's `messages`, `users`, `me`, `lastReadAt`, `typing`, `onReact`, `onEdit`, `onDelete`, `onPin`, `pinnedIds`, `onStar`, `onCopy`, `onAttach` and the open handlers, plus:

| Prop | Type | Default |
| --- | --- | --- |
| `onSend` | `(text, { attachments }) => void` | |
| `onOpenThread` | `(messageId) => void`: the replies summary and Reply in thread | |
| `plain` | `boolean`: a thread's panel, the parent first with a reply count under it | `false` |
| `header` | `ReactElement`, at the top of the list | |
| `composerFooter` | `ReactNode`, under the box: "Also send to #design" | |

### ConversationList

| Prop | Type | Default |
| --- | --- | --- |
| `conversations` | `MessengerConversation[]` | |
| `me` | `string` | |
| `users` | `Record<id, MessengerUser>`, for "Maya: …" in groups | |
| `active` | `string` | |
| `onSelect` | `(id) => void` | |
| `onPin`, `onMute`, `onArchive` | `(id) => void`: swipe actions | |
| `header` | `ReactElement`, above the rows | |

### MessengerComposer

| Prop | Type | Default |
| --- | --- | --- |
| `value`, `onValueChange` | `string`, `(text) => void` | |
| `onSend` | `(text) => void` | |
| `variant` | `'pill' \| 'box'` | `'pill'` |
| `users`, `me` | who `@` suggests | |
| `context` | `{ kind: 'reply' \| 'edit', title, text, onCancel }` | |
| `pending`, `onRemovePending` | files waiting to go | |
| `onAttach`, `attachKinds` | the + menu | |
| `onSendVoice`, `onRecordStart`, `onRecordEnd`, `amplitude` | voice recording | |
| `footer` | `ReactNode`, under the box in `'box'` | |

### ChatDetails

| Prop | Type | Default |
| --- | --- | --- |
| `title`, `avatar`, `subtitle`, `group` | the conversation | |
| `participants` | `MessengerUser[]` | |
| `messages`, `me` | for the starred messages and the Media, Files and Links tabs | |
| `muted`, `onMutedChange` | `boolean`, `(muted) => void` | |
| `onSearch`, `onAudioCall`, `onVideoCall`, `onClose` | `() => void` | |
| `onSelectMessage` | `(messageId) => void`: a starred message | |

## Related

- [Team chat](../pro/team-chat): a Slack-style screen built from `ChannelThread`.
- [AI Chat](./ai-chat): an assistant that streams.
- [MessageBubble & ChatComposer](../components/chat): the free parts.
