React Native · Components
Chat
Chat screen: messaging like WhatsApp or an AI chat like ChatGPT, with the same message data and prop names as web.
Live example
The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.
Preview
Code
Events
- Events appear here when you interact with the preview.
Import
Chat
componentChat screen: messaging like WhatsApp or an AI chat like ChatGPT, with the same message data and prop names as web. Grouping, day headers, text formatting and stream reading live in the shared core (@yasinsensoy/core/chat).
- List: an inverted
FlatList; the newest message at the bottom,onLoadMorewhen scrolling up. While scrolled up, a "jump to latest" button and the new message count. - Message: press and hold for a menu (react, reply, copy, edit, delete…), swipe right to reply, reaction chips, read ticks, attachments.
- AI: thinking time, tool calls, sources, error and retry; copy / regenerate / rate below the response.
- Keyboard: on iOS the composer moves above the keyboard.
Examples
TypingIndicator
componentThree bouncing dots (same as web). Chat shows it itself; it can also be used on its own in a header or contact list.
Examples
ChatComposer
componentThe chat's composer: for messaging and AI prompts. Grows as you type (up to 6 lines), attachments show with small previews, reply and edit bars appear on top; while streaming the send button becomes "Stop". Chat renders it itself; it can also be used on its own.
Examples
parseStreamData
functionTurns an SSE data: line into a part. Recognizes your own part objects (type field), OpenAI (choices[0].delta.content), Anthropic (delta.text, delta.thinking) and { text | content | delta }; when it is not JSON it is the text itself. [DONE] and unknown ones are null.
toggleReaction
functionToggles a reaction and returns the new list (does not mutate the array). With single (default, like WhatsApp) the person's previous reaction is removed.
Examples
readChatStream
functionTurns a stream into parts: Response (fetch), ReadableStream, AsyncIterable or a single text. In SSE responses data: lines are decoded with parse (default parseStreamData).
Examples
applyStreamPart
functionApplies a part to a message and returns the new message.
defaultChatMessages
constantTurkish chat texts.
enChatMessages
constantEnglish chat texts (the web en dictionary and React Native use the same text).
useChat
functionManages the state of an AI chat (same API as web's useChat): keeps the messages, reads the response as a stream, stops, regenerates and edits. Chunks render once per frame; thinking time is measured.
Examples
ChatMode
typeChat type: messaging like WhatsApp or an AI chat like ChatGPT.
ChatSuggestion
typeSuggestion chip: text, or a separate label + prompt.
ChatProps
interfaceProps of Chat (same names as web).
| Name | Type | Default | Description |
|---|---|---|---|
messages | readonly ChatMessage[] | Messages, oldest to newest. | |
mode? | ChatMode | "messaging" | Type. |
currentUserId? | string | Your own user ID: whether a message is drawn on the right or the left. | |
users? | readonly ChatUser[] | People (name, avatar). | |
group? | boolean | true` if there are more than 2 people | Group chat: names and avatars are shown. |
status? | ChatStatus | AI status. | |
onSend? | (draft: ChatDraft) => unknown | When a message is sent. | |
onStop? | () => void | When "Stop" is pressed. | |
onReact? | (message: ChatMessage, emoji: string) => void | When a reaction is given (toggle with toggleReaction). | |
onEdit? | (message: ChatMessage, text: string) => unknown | When a message is edited. | |
onDelete? | (message: ChatMessage) => unknown | When a message is deleted. | |
onForward? | (message: ChatMessage) => void | Forward. | |
onStar? | (message: ChatMessage) => void | Star. | |
onPin? | (message: ChatMessage) => void | Pin. | |
onRetry? | (message: ChatMessage) => void | When a failed message or an errored response is tapped. | |
onRegenerate? | (message: ChatMessage) => void | Regenerate the response. | |
onFeedback? | (message: ChatMessage, value: "up" | "down" | null) => void | 👍/👎. | |
onCopy? | (message: ChatMessage) => void | Copy: the app writes to the clipboard (no extra dependency). The action is hidden if not given. | |
actions? | readonly ChatActionName[] | Only these actions are shown. | |
customActions? | readonly ChatCustomAction[] | Custom actions added to the menu. | |
canEdit? | (message: ChatMessage) => boolean | own messages that are not deleted | Can a message be edited? |
canDelete? | (message: ChatMessage) => boolean | own messages that are not deleted | Can a message be deleted? |
confirmDelete? | boolean | true | Ask before deleting. |
quickReactions? | readonly string[] | Quick reactions in the menu. | |
typing? | readonly string[] | IDs of the people typing ("Jane is typing…"). | |
hasMore? | boolean | false | Are there older messages? |
onLoadMore? | () => unknown | Fetches older messages when scrolling up; the indicator spins until the Promise settles. | |
unreadFrom? | string | "Unread" divider starting from this message. | |
suggestions? | readonly ChatSuggestion[] | Suggestion chips in an empty chat. | |
empty? | ReactNode | Content shown when empty. | |
header? | ReactNode | Header at the top (e.g. person name, avatar). | |
composer? | Partial<Omit<ChatComposerProps, "onSend">> | false | Composer settings; false hides it. | |
groupWindow? | number | 5 minutes | Messages from the same person within this time (ms) form one block. |
collapseAfter? | number | 700 | Messages longer than this many characters are shortened with "Read more". |
swipeToReply? | boolean | true | Swipe a message right to reply. |
timeZone? | string | Time zone. | |
texts? | Partial<ChatMessages> | Texts of this chat. | |
onOpenAttachment? | (attachment: ChatAttachment, message: ChatMessage) => void | When an attachment (image, file) is tapped; fullscreen or opening is up to the app. | |
style? | StyleProp<ViewStyle> | Container style. |
TypingIndicatorProps
interfaceThree bouncing dots: the "typing…" and "thinking" state.
| Name | Type | Default | Description |
|---|---|---|---|
label? | string | Text read by screen readers (e.g. "Jane is typing…"). | |
color? | string | the muted text color | Dot color. |
style? | StyleProp<ViewStyle> | Container style. |
Composer look: messaging or an AI prompt.
ChatComposerHandle
interfaceMethods of the ChatComposer ref.
| Name | Type | Description |
|---|---|---|
focus | () => void | Focuses the input. |
addFiles | (files: Iterable<ChatFile>) => void | Adds files (at most maxFiles). |
insertText | (text: string) => void | Appends to the end of the text. |
clear | () => void | Clears the text and attachments. |
ChatComposerProps
interfaceProps of ChatComposer (same names as web).
| Name | Type | Default | Description |
|---|---|---|---|
onSend | (draft: ChatDraft) => unknown | With the draft when sent. | |
value? | string | Text (controlled). | |
defaultValue? | string | Initial text. | |
onValueChange? | (value: string) => void | When the text changes. | |
variant? | ChatComposerVariant | "messaging" | Look. |
placeholder? | string | Placeholder. | |
disabled? | boolean | Disabled. | |
status? | ChatStatus | "ready" | AI status; while streaming the send button becomes "Stop". |
onStop? | () => void | When "Stop" is pressed. | |
onPickFiles? | () => Promise<readonly ChatFile[] | undefined | null> | readonly ChatFile[] | Paperclip button: called on tap; return the chosen files (your own image/document picker). The component uses no extra dependency. | |
maxFiles? | number | 10 | Maximum files in one message. |
replyTo? | ChatMessage | null | The message being replied to. | |
replyAuthor? | ReactNode | Author of the message being replied to. | |
replyColor? | string | Color of the reply bar. | |
onCancelReply? | () => void | When the reply is dismissed. | |
editing? | ChatMessage | null | The message being edited. | |
onCancelEdit? | () => void | When editing is dismissed. | |
maxLength? | number | Maximum characters. | |
toolbar? | ReactNode | Extra buttons to the left of the input. | |
footer? | ReactNode | Content below the input. | |
onTyping? | () => void | Called while typing (at most once every 3 seconds): for the "typing…" status. | |
autoFocus? | boolean | Focus on mount. | |
ref? | Ref<ChatComposerHandle> | Control functions. | |
messages? | Partial<ChatMessages> | Texts of this composer. |
ChatMessages
interfaceTexts of the chat components (Chat, ChatComposer, EmojiPicker). Replace them app-wide in the dictionary's ui.chat namespace, or for one chat with the messages prop. Placeholders such as {count} and {name} are filled at runtime.
| Name | Type | Default | Description |
|---|---|---|---|
list | string | "Mesajlar" | Screen reader name of the message list. |
you | string | "Sen" | Author of your own messages (in quotes, reactions). |
unread | string | "{count} okunmamış mesaj" | Unread messages separator. |
jumpToLatest | string | "En yeni mesajlara git" | Scroll down button. |
newMessages | string | "{count} yeni mesaj" | Count of new messages that arrived while scrolled up. |
loadingOlder | string | "Eski mesajlar yükleniyor…" | While older messages load. |
edited | string | "düzenlendi" | Note next to the time of an edited message. |
deleted | string | "Bu mesaj silindi" | Deleted message. |
deletedOwn | string | "Bu mesajı sildin" | Your own deleted message. |
forwarded | string | "İletildi" | Note above a forwarded message. |
readMore | string | "Devamını oku" | Link that expands a long message. |
sending | string | "Gönderiliyor" | Delivery status. |
sent | string | "Gönderildi" | Delivery status: single tick. |
delivered | string | "Teslim edildi" | Delivery status: double tick. |
read | string | "Okundu" | Delivery status: blue double tick. |
failed | string | "Gönderilemedi. Yeniden denemek için dokun." | Message that failed to send. |
starred | string | "Yıldızlı" | Starred message marker. |
pinned | string | "Sabitlendi" | Pinned message marker. |
react | string | "Tepki ver" | Reaction button. |
reply | string | "Yanıtla" | Reply action. |
copy | string | "Kopyala" | Copy action. |
copied | string | "Kopyalandı" | After copying. |
edit | string | "Düzenle" | Edit action. |
delete | string | "Sil" | Delete action. |
forward | string | "İlet" | Forward action. |
star | string | "Yıldızla" | Star action. |
unstar | string | "Yıldızı kaldır" | Unstar action. |
pin | string | "Sabitle" | Pin action. |
unpin | string | "Sabitlemeyi kaldır" | Unpin action. |
retry | string | "Yeniden dene" | Retry action. |
regenerate | string | "Yeniden oluştur" | Regenerate response action. |
good | string | "İyi yanıt" | Like button. |
bad | string | "Kötü yanıt" | Dislike button. |
more | string | "Diğer" | More actions menu. |
moreReactions | string | "Diğer emojiler" | + button in the reaction bar. |
messageActions | string | "Mesaj eylemleri" | Screen reader name of the action panel. |
deleteTitle | string | "Mesaj silinsin mi?" | Delete confirmation title. |
deleteDescription | string | "Mesaj herkes için silinir." | Delete confirmation description. |
reactedBy | string | "{names} tepki verdi" | Tooltip of a reaction chip. |
typing | string | "{name} yazıyor…" | While one person types. |
typingTwo | string | "{a} ve {b} yazıyor…" | While two people type. |
typingMany | string | "{count} kişi yazıyor…" | While three or more people type. |
thinking | string | "Düşünüyor…" | While thinking. |
thought | string | "Düşünme" | Thinking section of unknown duration. |
thoughtFor | string | "{seconds} sn düşündü" | Thinking duration. |
toolRunning | string | "Çalışıyor" | Tool running. |
toolDone | string | "Tamamlandı" | Tool finished. |
toolError | string | "Hata" | Tool failed. |
toolInput | string | "Girdi" | Tool input title. |
toolOutput | string | "Çıktı" | Tool output title. |
sources | string | "Kaynaklar" | Sources list. |
errorTitle | string | "Yanıt alınamadı" | Default text of the error box. |
placeholder | string | "Mesaj yaz" | Placeholder of the input in messaging. |
placeholderAssistant | string | "Bir şey sor…" | Placeholder in AI chat. |
send | string | "Gönder" | Send button. |
stop | string | "Durdur" | Stop response button. |
attach | string | "Dosya ekle" | Attach file button. |
emoji | string | "Emoji" | Emoji button. |
record | string | "Sesli mesaj kaydet" | Record button. |
sendRecording | string | "Sesli mesajı gönder" | Finish and send the recording. |
cancelRecording | string | "Kaydı sil" | Cancel the recording. |
recording | string | "Kaydediliyor" | While recording. |
micDenied | string | "Mikrofona erişilemedi" | When there is no microphone permission. |
replyingTo | string | "{name} yanıtlanıyor" | Reply bar. |
cancelReply | string | "Yanıtı iptal et" | Close the reply bar. |
editing | string | "Mesajı düzenliyorsun" | Edit bar. |
cancelEdit | string | "Düzenlemeyi iptal et" | Close the edit bar. |
removeFile | string | "{name} kaldır" | Remove button in the attachment preview. |
dropFiles | string | "Dosyaları buraya bırak" | Drag and drop area. |
tooManyFiles | string | "En fazla {max} dosya eklenebilir" | When the file limit is exceeded. |
fileTooLarge | string | "{name} çok büyük (en fazla {max})" | When the size limit is exceeded. |
fileNotAccepted | string | "{name} desteklenmiyor" | When the type is not accepted. |
voiceMessage | string | "Sesli mesaj" | Voice message attachment. |
photo | string | "Fotoğraf" | Image attachment (in quotes). |
video | string | "Video" | Video attachment (in quotes). |
file | string | "Dosya" | File attachment (in quotes). |
play | string | "Oynat" | Play the voice message. |
pause | string | "Duraklat" | Pause the voice message. |
speed | string | "Oynatma hızı" | Speed button. |
download | string | "İndir" | Download the file. |
openMedia | string | "Tam ekran aç" | Open the image/video full screen. |
moreMedia | string | "+{count}" | Count of attachments that do not fit the grid. |
emptyTitle | string | "Henüz mesaj yok" | Empty messaging. |
emptyAssistant | string | "Nasıl yardımcı olabilirim?" | Empty AI chat. |
suggestions | string | "Öneriler" | Screen reader name of the suggestion chips. |
emojiRecent | string | "Son kullanılanlar" | Emoji category. |
emojiSmileys | string | "Yüzler" | Emoji category. |
emojiPeople | string | "İnsanlar" | Emoji category. |
emojiNature | string | "Doğa" | Emoji category. |
emojiFood | string | "Yiyecek" | Emoji category. |
emojiActivity | string | "Etkinlik" | Emoji category. |
emojiTravel | string | "Seyahat" | Emoji category. |
emojiObjects | string | "Nesneler" | Emoji category. |
emojiSymbols | string | "Semboller" | Emoji category. |
ChatStreamPart
typeA part coming from the stream. A plain text part (string) is appended to the response.
{ type: "text", text }: Text appended to the response.{ type: "reasoning", text }: Text appended to the thinking section.{ type: "tool", id, ... }: A tool call; the sameidis updated.{ type: "source", url, title }: Adds a source.{ type: "message", message }: Changes message fields directly (e.g.{ attachments },{ body }).{ type: "error", error }: The response ends with an error.
ChatDate
typeValues accepted as dates: Date, an ISO string or milliseconds.
ChatRole
typeRole of the message author.
"user": The person using the app (on the right)."assistant": The AI or the other party (on the left)."system": Small info line in the middle ("Ayşe joined the group").
ChatToolCall
typeA tool call by the AI.
ChatSource
typeA source the response is based on.
ChatLinkPreview
typeLink preview.
ChatMessage
typeA chat message (same fields as web).
Delivery status of a message; shows as ticks next to the time of your own messages (like WhatsApp).
"sending": Sending (clock icon)."sent": Reached the server (single tick)."delivered": Reached the recipient (double tick)."read": Read (blue double tick)."failed": Failed to send (red warning; tap to retry).
ChatFile
interfaceA file added to the composer. The app provides the picker (e.g. your own image picker); the component only shows and sends it.
| Name | Type | Description |
|---|---|---|
uri | string | URL of the file (file://, content://, https://). |
name? | string | File name. |
type? | string | MIME type (image/jpeg). |
size? | number | Size (bytes). |
width? | number | Image width (px). |
height? | number | Image height (px). |
ChatUser
interfaceA person in the chat.
| Name | Type | Description |
|---|---|---|
id | string | Unique id; matches the messages' authorId. |
name | string | Display name. |
avatar? | string | Profile photo. |
color? | string | Name color in group chats (e.g. "#e11d48", "var(--ui-primary)"). When omitted, a stable color is picked from the id. |
status? | "online" | "away" | "busy" | "offline" | Online status; a dot on the avatar's corner. |
ChatCustomAction
interfaceCustom action added to the message menu.
| Name | Type | Description |
|---|---|---|
label | string | Display name. |
icon? | IconProp | Icon. |
tone? | "neutral" | "danger" | Red (dangerous) action. |
onSelect | (message: ChatMessage) => void | Called with the message when chosen. |
when? | (message: ChatMessage) => boolean | Show only on these messages. |
Attachment kind. When omitted, it is derived from type (MIME) or the file name.
"image","video": Thumbnail in a grid; full screen on click."audio": Voice message player (waveform, speed)."file": File card (icon, name, size, download).
ChatDraft
interfaceDraft sent from the composer (same as web; files are ChatFile).
| Name | Type | Description |
|---|---|---|
text | string | Text (trimmed). |
files | ChatFile[] | Attached files. |
replyTo? | ChatMessage | The message being replied to. |
ChatAttachment
interfaceMessage attachment: image, video, audio or file.
| Name | Type | Description |
|---|---|---|
id? | string | Unique id. When omitted, url or the name is used. |
name? | string | File name. |
url? | string | Address (download, playback, full screen). A local preview can be given while uploading. |
type? | string | MIME type (e.g. "image/png", "audio/webm"). |
kind? | ChatAttachmentKind | Kind. See ChatAttachmentKind. |
size? | number | Size (bytes). |
thumbnail? | string | Thumbnail (shown in the grid instead of url). |
width? | number | Natural width (px); when given, space is reserved before the image loads, so nothing shifts. |
height? | number | Natural height (px). |
duration? | number | Duration of audio and video (seconds). |
waveform? | readonly number[] | Waveform of a voice message: samples between 0 and 1 (30-60 are enough). When omitted, a fixed pattern is drawn. |
progress? | number | Upload progress (0-1). When given, a ring shows over the attachment. |
ChatReaction
interfaceA reaction: the emoji and who reacted.
| Name | Type | Description |
|---|---|---|
emoji | string | Emoji (e.g. "👍"). |
users | readonly string[] | Ids of the people who reacted. The count is its length. |
ChatReasoning
interfaceA thinking step of the AI.
| Name | Type | Description |
|---|---|---|
text | string | Thinking text (Markdown). |
duration? | number | Thinking duration (seconds); written as "Thought for 12 s". |
ChatActionName
typeNames of the actions on a message. ChatProps.actions picks which actions show.
ChatStatus
typeChat state (AI). While "submitted" and "streaming", the send button becomes "Stop".
"ready": Ready."submitted": Request sent, waiting for the first part (three dots)."streaming": The response is streaming."error": The last request failed.
ChatSendContext
interfaceInfo passed to UseChatOptions.send.
| Name | Type | Description |
|---|---|---|
messages | ChatMessage[] | History to respond to: the last message is the user's new message. |
signal | AbortSignal | Aborted when "Stop" is pressed; pass it to fetch. |
files | ChatFile[] | Files the user attached (to the last message). |
ChatSendResult
typeResponses the send function can return: a fetch response (read even if it does not stream; SSE, OpenAI and Anthropic formats are recognized), a stream, an async function* generator or text.
UseChatOptions
interfaceOptions of useChat (same as web).
| Name | Type | Description |
|---|---|---|
send | (context: ChatSendContext) => ChatSendResult | Promise<ChatSendResult> | Produces the response. |
initialMessages? | readonly ChatMessage[] | Initial messages. |
parse? | (data: string) => ChatStreamPart | null | Parsing of an SSE data: line. |
onFinish? | (message: ChatMessage, messages: ChatMessage[]) => void | When the response ends (even if stopped). |
onError? | (error: unknown) => void | When the request fails. |
onFeedback? | (message: ChatMessage, value: "up" | "down" | null) => void | When the user gives 👍/👎. |
attachment? | (file: ChatFile) => ChatAttachment | Promise<ChatAttachment> | Turns an added file into a message attachment (e.g. upload and return its URL). Defaults to the local URL. |
generateId? | () => string | Generates a new message ID. |
UseChatResult
interfaceResult of useChat (same as web).
| Name | Type | Description |
|---|---|---|
messages | ChatMessage[] | Messages. |
setMessages | (messages: ChatMessage[] | ((current: ChatMessage[]) => ChatMessage[])) => void | Changes the messages directly. |
status | ChatStatus | Status. |
error | unknown | Last error. |
send | (input: string | ChatDraft) => Promise<void> | Sends a message (text or a draft). |
stop | () => void | Stops the streaming response. |
regenerate | (message?: ChatMessage) => Promise<void> | Regenerates the last (or the given) response. |
edit | (message: ChatMessage, text: string) => Promise<void> | Edits a user message and regenerates what follows. |
props | { messages: ChatMessage[]; status: ChatStatus; onSend: (draft: ChatDraft) => Promise<void>; onStop: () => void; onRegenerate: (message: ChatMessage) => void; onRetry: (message: ChatMessage) => void; onEdit: (message: ChatMessage, text: string) => Promise<void>; onFeedback: (message: ChatMessage, value: "up" | "down" | null) => void; } | Props to spread onto Chat: <Chat mode="assistant" {...chat.props} />. |