# React Native Chat Bubble, Composer, Typing Indicator & Suggestions

> React Native chat UI for iOS, Android and the web: message bubbles in iOS, Material 3 and web styles, a composer that grows with the text and sends on Enter, a typing indicator and quick-reply suggestion chips. For messaging apps and AI assistants.

# MessageBubble & ChatComposer

The parts of a chat: `MessageBubble` for each message, `ChatComposer`, the box under the thread that starts at one line, grows with the text and sends on the button or Enter (Shift+Enter for a new line), `TypingIndicator` while a reply is being written, and `SuggestionChips` for quick replies. Bubbles are round on iOS, have a small corner on the sender's side in Material and brand, and are outlined on the web.

For an AI assistant with streaming Markdown replies, reasoning, tool calls, stop, retry and history, see Pro [AI Chat](../blocks/ai-chat).

```tsx live
import { useState } from 'react';

export default function Example() {
  const [messages, setMessages] = useState([
    { id: 1, from: 'them', text: 'See you at 7 by the river?' },
    { id: 2, from: 'me', text: 'Perfect, I’ll bring snacks.' },
  ]);
  return (
    <VStack gap="sm" style={{ width: '100%', maxWidth: 360 }}>
      {messages.map((m) => (
        <MessageBubble key={m.id} from={m.from}>
          {m.text}
        </MessageBubble>
      ))}
      <ChatComposer onSend={(text) => setMessages((all) => [...all, { id: Date.now(), from: 'me', text }])} />
    </VStack>
  );
}
```

## Anatomy

A chat screen is four parts you lay out yourself, usually in a `FlatList` above a composer:

```tsx
<VStack>
  <MessageBubble from="them" />   {/* their message, at the start */}
  <MessageBubble from="me" />     {/* yours, at the end */}
  <TypingIndicator />             {/* while they write */}
  <SuggestionChips />             {/* quick replies */}
  <ChatComposer />                {/* the input and Send */}
</VStack>
```

## Examples

Each example is live: edit the code and it runs.

### A support chat

A store's help chat: the agent's messages carry a name and a time, quick replies answer the last question, and the agent types back after each message.

```tsx live
import { useState } from 'react';
import { ChatComposer, MessageBubble, SuggestionChips, TypingIndicator, VStack } from 'patine-ui';

const AGENT = 'Jonah · Support';
const FIRST = [
  { id: 1, from: 'them', text: 'Hi Sara, I see order #48213 (Trail runner GTX, size 9). How can I help?', meta: '10:02' },
  { id: 2, from: 'me', text: 'They fit a bit small. Can I swap them for a 9.5?', meta: '10:03' },
  { id: 3, from: 'them', text: 'Of course. Size 9.5 is in stock. Should I send a free return label to your email?', meta: '10:03' },
];
const now = () => new Date().toLocaleTimeString('en-US', { hour: 'numeric', minute: '2-digit' });

export default function Example() {
  const [messages, setMessages] = useState(FIRST);
  const [typing, setTyping] = useState(false);
  const send = (text: string) => {
    setMessages((all) => [...all, { id: Date.now(), from: 'me', text, meta: now() }]);
    setTyping(true);
    setTimeout(() => {
      setTyping(false);
      const reply = 'Done! The label is on its way, and the 9.5 ships as soon as the pair is scanned.';
      setMessages((all) => [...all, { id: Date.now(), from: 'them', text: reply, meta: now() }]);
    }, 1500);
  };
  const last = messages[messages.length - 1];
  return (
    <VStack gap="sm" style={{ width: '100%', maxWidth: 380 }}>
      {messages.map((m) => (
        <MessageBubble key={m.id} from={m.from as 'me' | 'them'} name={m.from === 'them' ? AGENT : undefined} meta={m.meta}>
          {m.text}
        </MessageBubble>
      ))}
      {typing ? <TypingIndicator name="Jonah" /> : null}
      {last.from === 'them' && !typing ? (
        <SuggestionChips suggestions={['Yes, please', 'Send it by text', 'I’ll keep them']} onPress={send} />
      ) : null}
      <ChatComposer placeholder="Message Jonah" onSend={send} sending={typing} />
    </VStack>
  );
}
```

### Typing indicator

`TypingIndicator` shows three dots in an incoming bubble while someone, or an assistant, writes a reply. Screen readers hear "Maya is typing" when it appears (or "Typing" without a `name`); the dots hold still when the OS asks to reduce motion.

```tsx live
import { MessageBubble, TypingIndicator, VStack } from 'patine-ui';

export default function Example() {
  return (
    <VStack gap="sm" style={{ width: '100%', maxWidth: 360 }}>
      <MessageBubble from="me">Is the 7pm table still free?</MessageBubble>
      <TypingIndicator name="Maya" />
    </VStack>
  );
}
```

### Suggestions

`SuggestionChips` is a row of quick replies that scrolls sideways: prompts to start a chat from, or answers to the last question. `onPress` gets the chip's text, e.g. to send it.

```tsx live
import { useState } from 'react';
import { ChatComposer, MessageBubble, SuggestionChips, VStack } from 'patine-ui';

const REPLIES = ['Track my order', 'Change the address', 'Talk to a person'];

export default function Example() {
  const [messages, setMessages] = useState([{ id: 1, from: 'them', text: 'Hi! How can I help?' }]);
  const send = (text) => setMessages((all) => [...all, { id: Date.now(), from: 'me', text }]);
  return (
    <VStack gap="sm" style={{ width: '100%', maxWidth: 360 }}>
      {messages.map((m) => (
        <MessageBubble key={m.id} from={m.from}>
          {m.text}
        </MessageBubble>
      ))}
      {messages.length === 1 ? <SuggestionChips suggestions={REPLIES} onPress={send} /> : null}
      <ChatComposer onSend={send} />
    </VStack>
  );
}
```

## In real apps

Patine Pro screens built with it. Each opens on that screen, live, in the screens gallery.

## Designs

Bubbles follow each platform: iOS's blue tails, Material's rounded tonal bubbles, and the web's flat ones.

<DesignsGrid
  example={
    <>

        Is the 7pm table free?
        Yes, for two.

    </>
  }
/>

## Guidelines

<Do preview={<></>}>

**Offer a few short suggestions.** Two to four replies people would actually send.

<Dont preview={<></>}>

**Don't write paragraphs as chips.** Long chips wrap and are slower to read than to type.

**Name who's speaking in a group.** `name` above a bubble tells people apart.

<Dont preview={<></>}>

**Don't disable Send without a reason.** It's off only while the message is empty, which people can see.

## Accessibility

| | Behaviour |
| --- | --- |
| Role | Bubbles are text (selectable); the composer's input is named "Message" and its button "Send" (both through `labels`); suggestions are buttons. |
| Announced | Send is `disabled` until there's text and `busy` while `sending`; with `onStop` it becomes Stop. |
| Keyboard (web) | Enter sends and Shift+Enter adds a line on the web; suggestions take Tab focus. |
| Touch target | Send, Stop and every suggestion have a 44pt touch area. |
| Reduce motion | The typing dots hold still with reduce motion on. |

## API

### MessageBubble

MessageBubble also takes `View` props.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` | — | The message: a string, or any content. |
| `from` | `'me' \| 'them'` | `'them'` | `'me'` sits at the end in the primary color. |
| `name` | `string` | — | The sender's name above the bubble. |
| `meta` | `string` | — | Under the bubble, e.g. the time. |
| `styles` | `{ bubble?: StyleProp<ViewStyle>; text?: StyleProp<TextStyle> }` | — | Style slots: `bubble` and the message `text`. |
| `theme` / `design` | | | The theme override and the look to follow, as on every component. |

### ChatComposer

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `onSend` | `(text: string) => void` | **Required** | Required. Gets the trimmed text; the composer then clears. |
| `value` / `defaultValue` / `onValueChange` | `string` | — | Controlled or uncontrolled text. |
| `placeholder` | `string` | `'Message'` | |
| `disabled` | `boolean` | `false` | Blocks typing and sending. |
| `sending` | `boolean` | `false` | A spinner on the send button; blocks sending. |
| `onStop` | `() => void` | — | While `sending`, the send button becomes Stop and Escape calls it, e.g. to stop an assistant's reply. |
| `leading` | `ReactNode` | — | Before the input, e.g. an attach button. |
| `maxRows` | `number` | `5` | Lines before the input scrolls. |
| `labels` | `{ input, send, stop }` | `'Message'`, `'Send'`, `'Stop'` | For translation. |
| `style` | `StyleProp<ViewStyle>` | — | The composer's box. |
| `theme` / `design` | | | The theme override and the look to follow, as on every component. |

### TypingIndicator

TypingIndicator also takes `View` props.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `name` | `string` | — | Who is typing, for screen readers: "Maya is typing". Without it: "Typing". |
| `accessibilityLabel` | `string` | — | Replaces what screen readers say. |
| `style` | `StyleProp<ViewStyle>` | — | The bubble. |
| `theme` / `design` | | | The theme override and the look to follow, as on every component. |

### SuggestionChips

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `suggestions` | `readonly string[]` | **Required** | Required. The replies or prompts, in order; each is its label and the value `onPress` gets. |
| `onPress` | `(suggestion: string) => void` | **Required** | Required. Called with the suggestion the user picks. |
| `disabled` | `boolean` | `false` | Blocks every chip, e.g. while an assistant replies. |
| `accessibilityLabel` | `string` | `'Suggestions'` | Names the group for screen readers. |
| `style` | `StyleProp<ViewStyle>` | — | The row. |
| `theme` / `design` | | | The theme override and the look to follow, as on every component. |

Right to left and custom styles work the same on every component: see [Internationalization and right to left](../guides/i18n-rtl) and [Styling](../guides/styling).
