Composable user and assistant message layouts for AI chat.
Composable user and assistant message layouts for AI chat.
import { ChatMessage } from 'heroui-native-pro';<ChatMessage.User>
<ChatMessage.Bubble>
<ChatMessage.Content>...</ChatMessage.Content>
</ChatMessage.Bubble>
</ChatMessage.User>
<ChatMessage.Assistant>
<ChatMessage.Avatar alt="..." />
<ChatMessage.Body>
<ChatMessage.Content>...</ChatMessage.Content>
<ChatMessage.Media>...</ChatMessage.Media>
<ChatMessage.Actions>
<ChatMessage.Action accessibilityLabel="...">...</ChatMessage.Action>
</ChatMessage.Actions>
</ChatMessage.Body>
</ChatMessage.Assistant>
<ChatMessage.Assistant variant="card">
<ChatMessage.Content>...</ChatMessage.Content>
...
</ChatMessage.Assistant>ChatMessage is a namespace of layout parts, not a root with children. Compose each turn explicitly and keep the message state in your app or AI SDK layer.
variant="card" a column on a heroui-native Card surface.Text with the message typography. Other nodes, such as Markdown, render as-is and style themselves.ChatMessageActions, the row of action buttons and its presets (ChatMessage.Actions.Copy, ...).Button). Also available as ChatMessageActions.Action. It has no visible label, so always pass an accessibilityLabel.Avatar built from src and fallback, or a same-size spacer when show is false. The spacer is hidden from screen readers.Compose a user turn with a bubble and an assistant turn with an avatar and a body.
<ChatMessage.User>
<ChatMessage.Bubble>
<ChatMessage.Content>How do compound components help chat UIs?</ChatMessage.Content>
</ChatMessage.Bubble>
</ChatMessage.User>
<ChatMessage.Assistant>
<ChatMessage.Avatar alt="Assistant" fallback="AI" />
<ChatMessage.Body>
<ChatMessage.Content>
They let you compose the layout explicitly while the state stays in your app.
</ChatMessage.Content>
</ChatMessage.Body>
</ChatMessage.Assistant>ChatMessageActions is the actions API: copy, feedback, regenerate, and menu presets with default icons and labels, plus ChatMessageActions.Action for custom buttons. ChatMessage.Actions is an alias of it. A custom action is an icon-only button with no visible label, so always pass an accessibilityLabel.
<ChatMessage.Body>
<ChatMessage.Content>...</ChatMessage.Content>
<ChatMessageActions>
<ChatMessageActions.Copy onPress={copyMessage} />
<ChatMessageActions.Action accessibilityLabel="Share" onPress={onShare}>
<ShareIcon size={16} color={mutedColor} />
</ChatMessageActions.Action>
</ChatMessageActions>
</ChatMessage.Body>variant="card" places the assistant turn on a heroui-native Card surface. The parts stack directly in a column, without an avatar or body.
<ChatMessage.Assistant variant="card">
<ChatMessage.Content>
Tailwind CSS v4.0 ships a faster engine and CSS-first configuration.
</ChatMessage.Content>
<Separator className="mt-1" />
<ChatSources.List>
<ChatSource href="https://tailwindcss.com/blog/tailwindcss-v4" title="Tailwind – Blog" />
</ChatSources.List>
</ChatMessage.Assistant>src accepts a URL or any React Native image source. fallback is shown while the image loads or when it fails. Without a fallback, heroui-native's default person icon is shown. Pass children to build the avatar content yourself.
<ChatMessage.Avatar alt="Assistant" src="https://example.com/bot.png" fallback="AI" />
<ChatMessage.Avatar alt="Assistant" src={require('./bot.png')} />
<ChatMessage.Avatar alt="Assistant" color="success" variant="soft" fallback="AI" />In consecutive assistant turns, set show={false} on every avatar after the first. The spacer keeps the bodies aligned.
<ChatMessage.Assistant>
<ChatMessage.Avatar alt="Assistant" fallback="AI" />
<ChatMessage.Body>...</ChatMessage.Body>
</ChatMessage.Assistant>
<ChatMessage.Assistant>
<ChatMessage.Avatar alt="Assistant" show={false} />
<ChatMessage.Body>...</ChatMessage.Body>
</ChatMessage.Assistant>The avatar and the spacer are both 32px. The avatar has no size prop. Resize it with className, and give every spacer in the thread the same class so the bodies stay aligned.
<ChatMessage.Avatar alt="Assistant" fallback="AI" className="size-10" />
<ChatMessage.Avatar alt="Assistant" show={false} className="size-10" />Place images or attachments in ChatMessage.Media, next to the bubble.
<ChatMessage.User>
<ChatMessage.Media>
<Image source={{ uri }} className="h-40 w-56 rounded-2xl" />
</ChatMessage.Media>
<ChatMessage.Bubble>
<ChatMessage.Content>What is in this photo?</ChatMessage.Content>
</ChatMessage.Bubble>
</ChatMessage.User>ChatMessage.Content wraps its children in a Text when they contain a string or number, so nested Text elements work for inline styling. Pass Text props such as selectable through textProps, and style the text with classNames.text. Any other children (a Markdown renderer, a card) render directly in the content container.
<ChatMessage.Content textProps={{ selectable: true }} classNames={{ text: 'text-base' }}>
Use <Text className="font-semibold">compound components</Text> to stay SDK-agnostic.
</ChatMessage.Content>
<ChatMessage.Content>
<Markdown>{markdown}</Markdown>
</ChatMessage.Content>animation="disable-all" on ChatMessage.User, ChatMessage.Assistant, or ChatMessage.Actions turns off every animation inside it: button press feedback, the avatar image fade, and the copy icon swap.
<ChatMessage.Assistant animation="disable-all">...</ChatMessage.Assistant>import { ChatMessage, ChatMessageActions } from 'heroui-native-pro';
import { ScrollView } from 'react-native';
type Message = {
id: number;
role: 'user' | 'assistant';
text: string;
};
const MESSAGES: Message[] = [
{ id: 0, role: 'user', text: 'Suggest a name for a hiking app.' },
{
id: 1,
role: 'assistant',
text: 'How about "Trailmark"? It is short and hints at progress on the trail.',
},
{ id: 2, role: 'user', text: 'Now a tagline for it.' },
{ id: 3, role: 'assistant', text: '"Every path, remembered."' },
];
export default function ChatMessageExample() {
return (
<ScrollView contentContainerClassName="gap-6 px-5 py-4">
{MESSAGES.map((message) =>
message.role === 'user' ? (
<ChatMessage.User key={message.id}>
<ChatMessage.Bubble>
<ChatMessage.Content>{message.text}</ChatMessage.Content>
</ChatMessage.Bubble>
</ChatMessage.User>
) : (
<ChatMessage.Assistant key={message.id}>
<ChatMessage.Avatar alt="Assistant" fallback="AI" />
<ChatMessage.Body>
<ChatMessage.Content>{message.text}</ChatMessage.Content>
<ChatMessageActions>
<ChatMessageActions.Copy />
<ChatMessageActions.ThumbsUp />
<ChatMessageActions.ThumbsDown />
</ChatMessageActions>
</ChatMessage.Body>
</ChatMessage.Assistant>
)
)}
</ScrollView>
);
}| prop | type | default | description |
|---|---|---|---|
children | ReactNode | - | Content of the turn, usually a ChatMessage.Bubble |
className | string | - | Additional CSS classes for the column |
animation | ChatMessageRootAnimation | - | Animation configuration of the turn |
...ViewProps | ViewProps | - | All standard React Native View props are supported |
Animation configuration for ChatMessage.User, ChatMessage.Assistant, and ChatMessage.Actions. The parts animate nothing themselves. Can be:
"disable-all": Disable all animations of descendants (button press feedback, avatar image fade, copy icon swap)undefined: Use default animations| prop | type | default | description |
|---|---|---|---|
children | ReactNode | - | Usually a ChatMessage.Avatar and a ChatMessage.Body. In a card, the parts directly |
variant | ChatMessageAssistantVariant | 'default' | 'card' places the turn on a heroui-native Card surface |
className | string | - | Additional CSS classes for the row (or the card) |
animation | ChatMessageRootAnimation | - | Animation configuration of the turn |
...ViewProps | ViewProps | - | All standard React Native View props are supported |
| value | description |
|---|---|
'default' | A row with the avatar next to the body |
'card' | A column on a heroui-native Card surface |
| prop | type | default | description |
|---|---|---|---|
children | ReactNode | - | Content, media, and actions of the turn |
className | string | - | Additional CSS classes for the column |
...ViewProps | ViewProps | - | All standard React Native View props are supported |
| prop | type | default | description |
|---|---|---|---|
children | ReactNode | - | Content of the bubble, usually a ChatMessage.Content |
className | string | - | Additional CSS classes for the bubble |
...ViewProps | ViewProps | - | All standard React Native View props are supported |
| prop | type | default | description |
|---|---|---|---|
children | ReactNode | - | Text (wrapped in a Text) or custom nodes (rendered as-is) |
className | string | - | Additional CSS classes for the container |
classNames | ElementSlots<ContentSlots> | - | Additional CSS classes for the slots |
styles | { container?: ViewStyle; text?: TextStyle } | - | Inline styles for the slots |
textProps | Omit<TextProps, 'children'> | - | Props for the Text wrapping text children (selectable, numberOfLines, …) |
...ViewProps | ViewProps | - | All standard React Native View props are supported |
| prop | type | description |
|---|---|---|
container | string | Custom class name for the content container |
text | string | Custom class name for the Text wrapping text children (text only) |
| prop | type | description |
|---|---|---|
container | ViewStyle | Styles for the content container |
text | TextStyle | Styles for the Text wrapping text children |
| prop | type | default | description |
|---|---|---|---|
children | ReactNode | - | Attachments of the turn (images, files) |
className | string | - | Additional CSS classes for the column |
...ViewProps | ViewProps | - | All standard React Native View props are supported |
Alias of ChatMessageActions. See ChatMessageActions for its presets.
| prop | type | default | description |
|---|---|---|---|
children | ReactNode | - | Action buttons |
className | string | - | Additional CSS classes for the row |
animation | ChatMessageRootAnimation | - | Animation configuration of the row |
...ViewProps | ViewProps | - | All standard React Native View props are supported |
| prop | type | default | description |
|---|---|---|---|
children | ReactNode | - | Icon of the button |
isIconOnly | boolean | true | Icon-only layout |
hitSlop | Insets | { top: 6, bottom: 6 } | Extra touch area. Makes the 32px button a 44pt tall target |
variant | ButtonVariant | 'ghost' | heroui-native Button variant |
size | ButtonSize | 'sm' | heroui-native Button size |
className | string | - | Additional CSS classes for the button |
accessibilityLabel | string | - | Label announced by screen readers. Always set it |
...ButtonRootProps | ButtonRootProps | - | All heroui-native Button props (onPress, animation, …) |
| prop | type | default | description |
|---|---|---|---|
children | ReactNode | - | Custom avatar content. Replaces the content built from src and fallback |
show | boolean | true | When false, renders a same-size spacer hidden from screen readers |
className | string | - | Additional CSS classes for the avatar or the spacer |
alt | string | - | Accessible description of the avatar, announced by screen readers. Required |
src | string | ImageSourcePropType | - | Image URL or any React Native image source |
fallback | string | - | Text shown while the image loads or when it fails |
...AvatarRootProps | Omit<AvatarRootProps, 'children' | 'alt' | 'size'> | - | All other heroui-native Avatar root props (color, variant, animation, …) |