Message

A chat message in its bubble, with its run, its status, a failed send, the sender's name and picture, the time and checks, a photo and a menu, and the chat's composer.

import { Composer, Message } from "@plexui/react-native"

Examples

Overview

Dates, service lines and unread messages

Platforms

iOS 27Android
Native componentNone: a messenger's bubbleNone: the Google Messages bubble
LookRadius 16 with 8 inside a run, the messenger's tail on the last of a run, the accent and a light grayRadius 20 with 4dp corners inside a run, no tail, the accent's soft container and the surface container
reactedA messenger's capsules in the bubble: 30 tall, the emoji and pictures of 24, the reader's in the accent; under a photo, outside it, the reader's white at 80% and others' black at 20% over the pageThe same capsules, the reader's in the primary
reactionsThe messenger's glass capsule over the lifted bubble, a tail of two drops to its corner, the menu under itA popup card 8dp over the bubble, the menu under it
timeThe messenger's time in the bubble: 11pt on the last line or the reactions' row, a dark capsule over a photoThe same, 11sp in the variant ink
authorThe messenger's name in the bubble over the words, 14 semibold in the sender's colorOver the bubble, Google Messages's caption
avatar34 at 7 by the last of a run, the bubbles at 4842 at 6, the bubbles 48 further in
receiptThe messenger's checks after the time, in the bubble's inkThe same checks in the time's ink
replyThe messenger's quote: 40 tall, corners of 4, a stripe of 3 and a fill at 10% in the quoted author's colorMaterial's quote: corners of 8, a stripe of 4 in the primary
roleAt the end of the name's line in the bubble, 13 in the time's colorAfter the name over the bubble
Message.Time, Message.SystemThe messenger's date and service pillsGoogle Messages's centered lines
Message.UnreadThe messenger's unread band: 25 tall edge to edge, 13 regular, white by dayThe messenger's compact strip: 27 tall, 14 medium, the surface container high
Message.PinnedNone: the messenger's glass capsule under the bar, 50 tall, the stripe and words in the label's color, its list button or cross at the endA surface container card, corners of 16, the stripe and the title in the primary
ComposerNone: a messenger's composer, Messages's send in the field. A glass "+" circle of 40 and a glass field of 40, 6 apart, 26 from the sides (8 over the keyboard), the send a 40×34 accent capsule inside the field once there is text, the transcript fading into the canvas behind it; the buttons are the kit's Button as a bar's itemsNone: the Google Messages composer. A field of 56 in the surface container with the add inside it, the send a circle of 56 in the primary color after it
Composer onVoiceA glass microphone circle of 40 after the field while it is empty; with text it goes and the field reaches the end, the send in itThe end circle with a microphone in the primary container, send once there is text

API

Message

PropTypeDefaultDescription
childrenReactNode—The words, set in the bubble's text with any inline text among them, or content of your own such as a photo; a Text inside takes the bubble's color unless it sets its own
direction"incoming" | "outgoing""incoming"outgoing stands at the trailing side in the sender's color; incoming at the leading side in gray
group"single" | "first" | "middle" | "last""single"The message's place in a run from one sender: the tail on iOS and the corners on Android follow it, and the space after it
statusReactNode—A line under the message at its side, such as Delivered or Read: Messages' words, not with a receipt
failedbooleanfalseThe message was not sent: no receipt, Not Delivered in red (on iOS with a receipt the mark alone), and a retry (a red mark beside the bubble on iOS, a press on the bubble on Android)
onRetry() => void—Called by the retry of a failed message
retryLabelstring"Try Again"The retry's name for assistive technologies
authorReactNode—The sender's name on the first of a run in a group chat: in the bubble over the words in the sender's color on iOS (an outgoing bubble's in its ink), over the bubble on Android and over a photo
authorColor"primary" | "secondary" | "success" | "info" | "discovery" | "danger"—The name's color on iOS in an incoming bubble, as an Avatar's color; by default the one a gradient Avatar of that name has
roleReactNode—The sender's role in the group (owner, admin), with author: at the end of the name's line on iOS, 13 in the time's color; after the name over the bubble on Android
reply{ author: ReactNode; text: ReactNode; picture?: ImageSourcePropType | ReactElement; color?: AvatarColor; onPress?: () => void }—The message it answers, quoted over its words: the author in their color (an Avatar's color sets another) over the words, one line each; onPress takes the app to it. picture puts what it answers (a photo, a video, a GIF) at the quote's start as the messenger's thumbnail: a square two of the author's lines tall (34 on iOS, 40 on Android), the picture cut to fill it, corners of 4, 4 under the quote's top and at its words' start, the words 6 after it; an image source, or an element of your own that fills its box. Leave it out for timed or hidden media, which the messenger quotes by name alone. Over a picture alone (media) the quote stands at the bubble's top as over words, in the bubble's fill, which frames the picture under it (6 under the quote on iOS, 4 on Android; its top corners those between the bubbles of a run); the bubble keeps its tail, and a long quote does not widen it
replyLabelstring"Reply to"The quote's name for assistive technologies, before its author and words
editedbooleanfalseThe message was changed after it was sent: edited before the time
editedLabelstring"edited"The edited mark's word
repliesnumber—How many answer it in its thread: an arrow and the count before the time, 1K past 1,000 and 3M past a million
repliesLabel(count: number) => string"1 reply", "3 replies"The count's words for assistive technologies
avatarReactNode—The sender's picture by the last of an incoming run, its foot on the bubble's (under a photo with reactions outside it, on theirs): an Avatar, set to 34 on iOS and 42 on Android unless it has a size; pass it to every message of the run
receipt"sending" | "sent" | "read"—The messenger's mark after an outgoing message's time: a turning clock while sending, one check when sent, two when read; not with a status. Its color is the bubble's own (--message-outgoing-check-color), the read checks' --message-outgoing-check-read-color
receiptLabelstring"Sending", "Sent" or "Read"The checks' words for assistive technologies, read after the time
mediabooleanfalseThe content fills the bubble, cut to its corners, with no padding: a photo (the messenger shows a 4:3 one 300 wide); on iOS a still Image, the last of a run with no reactions under it, has the tail, the picture drawn into it (a GIF, a blurred or tinted Image keeps its own drawing and no tail)
menuReactNode—ContextMenu items: a touch and hold lifts the bubble and opens them
reactionsReactNode—ContextMenu.AccessoryItems over the lifted bubble, with its menu: a row of reactions, More last; on iOS the messenger's capsule with its tail of two drops to the bubble's corner
reactionsLabelstring"Reactions"The reactions bar's name for assistive technologies
reactedReactNode—The reactions given, in the bubble under its content: Message.Reactions, a capsule each, wrapping onto more rows; under a photo, outside the bubble
timeReactNode—The time inside the bubble at its end: on the last line where there is room, at the end of the reactions' row, over a photo in a dark capsule
menuOpenboolean—The menu's open state, controlled
onMenuOpenChange(open: boolean) => void—Called when the menu opens or closes
onPress() => void—A press on the bubble
onLongPress() => void—A long press on the bubble, where there is no menu
accessibilityLabelstring—The bubble's name, for content that has no words of its own
accessibilityHintstring—What a press on the bubble does
styleStyleProp<ViewStyle>—Style of the row
bubbleStyleStyleProp<ViewStyle>—Style of the bubble
testIDstring—Test id of the row; the bubble is testID-bubble, the quote testID-reply and the retry testID-retry

Message.Reaction

PropTypeDefaultDescription
emojistring—The emoji given
avatarsReactNode—Who gave it: Avatars, set at 24 and overlapping by 10, each over the next and cut 1.5 around it, their initials Avatar's own, as a small conversation shows them
countnumber—How many gave it, in place of avatars, shortened as the messenger's: 1.2K, 12.3K, 3.4M
selectedbooleanfalseOne of them is the reader's: the capsule is filled with the accent
onPress() => void—A press on the capsule: take back or give the reaction
accessibilityLabelstringthe emoji, and the countIts name for assistive technologies
testIDstring—Test id

MESSAGE_REACTION holds its measures: height 30, start 11 (the emoji in), emoji 20 (its box), gap 4 (to the pictures), avatar 24, overlap 10, cut 1.5, avatarEnd 9 (7 with three pictures), countGap 5, count 11, countEnd 9. MESSAGE_TIME holds the time's: size 11, lineHeight 13, drop 4 (under the last line's baseline), rowBottom 0.5 (its box over the capsules' foot), and the photo's capsule (pill: height 18, inset 6, padding 7, fill black at 30%, color white). MESSAGE_RECEIPT holds the checks': width 11, height 9, room 13 (after the time), sent 1 and read 7 (their start after the time), top 8.47 (their box over the time's baseline), stroke 0.99. MESSAGE_PILL holds the pills': height 22, size 13, dateInset 6, serviceInset 7, margin 6 (over and under), edge 16 (from the screen's sides).

Message.Reactions

A message's reactions drawn as the messenger draws them, for reacted: one capsule for each emoji in the messenger's order, by how many gave it besides the reader (so giving one never moves a capsule), the reader's before an equal other's; each with the pictures of who gave it, the reader's first, while every giver is known (three reactions at most in all), else every capsule with its count.

PropTypeDefaultDescription
reactionsMessageReactions—The message's reactions: each emoji with how many gave it (the reader's with the order they chose it in) and who reacted last, three at most; toggleMessageReaction keeps them as the reader picks
avatar(peer: string) => ReactNodea gradient Avatar of that nameA picture of who gave one, by the name or id kept in reactions
onPress(emoji: string) => void—A press on a capsule: the reader takes theirs back or gives that one
partnerstring—A one-to-one conversation: the other person, whose picture stands in each capsule they gave, beside the reader's (me)
mestring—The reader, in a one-to-one conversation
channelbooleanfalseA channel's post: counts alone, no one's picture
testIDstring—Each capsule's test id is testID-emoji

Reactions kept

A message's reactions as the messenger keeps them (its open-source code's reactions attribute), a MessageReactions: results, each emoji given with its count and, for the reader's own, its chosenOrder; and recent, who reacted last, three at most, the newest at the end, the reader's marked mine. One capsule per emoji: a reaction someone has given already is joined, not drawn again.

  • toggleMessageReaction(reactions, emoji, me, { max }): the reader picks emoji, from the bar or a capsule. Their own is taken back; any other is theirs, joining that emoji's capsule (its count one more) or a new one at the end; past max of theirs (1, the messenger's for a reader without its subscription) the oldest goes, so a second reaction replaces the first.
  • setMessageReactions(reactions, chosen, me): the reader's set to chosen, oldest first, merged into the others' as the messenger merges its pending ones: one of theirs left out loses its one (and goes with it when it was theirs alone); the reader stands last among who reacted.
  • messageReactionItems(reactions, { partner, me, channel }): the capsules Message.Reactions draws, in its order, each with peers or null for a count.
  • messageReactionSummary(reactions): the menu's first row, how many reactions in all ("3 Reactions") and who reacted last, each once.
  • formatReactionCount(count): a count as a capsule shows it, 999, 1K, 1.2K, 3.4M.
  • MESSAGE_REACTIONS holds the limits (recent 3, max 1) and NO_MESSAGE_REACTIONS is a message with none.

Message.Time

PropTypeDefaultDescription
dayReactNode—The day: Today, Mon, November 28; in the pill on iOS, medium on Android
timeReactNode—A time after it: 09:41
childrenReactNode—Any content instead of day and time
styleStyleProp<ViewStyle>—Style of the line
testIDstring—Test id

Message.MediaBadge

A mark at a corner of a message's picture: a timed photo's seconds, a video's length. It stands in the capsule a photo's time stands in (MESSAGE_TIME.pill): white 11pt on black at 30%, 18 tall, its words 7 in, 6 from the picture's corner. Put it in the picture's own box, over it. It takes no press, and the bubble's name says what it marks.

The marks over a picture (this capsule, the photo's time and Message.MediaButton) stand on a blur of what is under them, as the messenger's do: --message-media-blur, 10px (0 for none), in a browser and on an iPhone with expo-blur. Android's views blur nothing under them, nor does Reduce Transparency: the fill stands alone there. A Spoiler with cover over the picture keeps its dust out from under the marks on every platform, so the dots drift under them, not through their fill.

PropTypeDefaultDescription
childrenReactNode—Its words (0:10), or content of its own; the kit's icons in it are white at 12
corner"top-start" | "top-end" | "bottom-start" | "bottom-end""top-start"The corner of the picture it stands at
styleStyleProp<ViewStyle>—Style of the capsule
testIDstring—Test id

Message.MediaButton

The round control over a message's picture (open, play, a timed photo's flame). It sits on the time capsule's fill, as the messenger's control over media shares the time's fill. It is an IconButton 2xl with its largest icon, white unless the icon sets its own color, in a box of its own so a centered picture centers it. It takes IconButton's props, except variant, color and mobileMaterial.

VoiceOver and TalkBack read a named or pressable bubble as one element, so the button inside it can't be reached on its own. Its press is offered as one of the bubble's actions, under the button's accessibilityLabel, as a quote's is.

Message.System

PropTypeDefaultDescription
childrenReactNode—The line: a person added, a message pinned; in the service pill on iOS, a name in it a Text with weight="semibold". Wrapped, a capsule for each line joined by hollowed corners
photoReactNode—The group's new photo under the line: content filling a square of 212 (an Image of width and height "100%"), on iOS in the messenger's frame 2 out of it, 8 under the words; on Android 8 under the line with corners of 16
styleStyleProp<ViewStyle>—Style of the line
testIDstring—Test id

Message.Unread

PropTypeDefaultDescription
childrenReactNode"Unread Messages"The band's words: "3 unread messages" or a translation
styleStyleProp<ViewStyle>—Style of the band
testIDstring—Test id

Message.Pinned

PropTypeDefaultDescription
childrenReactNode—The pinned message's words, on one line cut at its end
titleReactNode"Pinned Message"The title over them: "Pinned Message #2" for one of several, or a translation
countnumber1How many messages are pinned: a segment each in the stripe at the start
indexnumbercount - 1Which of them shows, 0 the first pinned (the stripe's top segment), drawn solid and the others at half
onPress() => void—A press on it: the app takes the conversation to the message (the messenger then shows the one pinned before it)
onList() => void—The list button at the end, for several pinned messages: the app shows them all
listLabelstring"All Pinned Messages"The list button's name for assistive technologies
onClose() => void—A cross at the end, where there is no list button: the app unpins the message or hides it
closeLabelstring"Unpin"The cross's name for assistive technologies
styleStyleProp<ViewStyle>—Style of the capsule
testIDstring—Test id; its end buttons are testID-list and testID-close

Composer

PropTypeDefaultDescription
valuestring—The text being written
onChangeText(text: string) => void—Called as the text changes
onSend() => void—Sends the text: the send button, and the return key in a browser
placeholderstring"Message"The field's placeholder and its name for assistive technologies
onAdd() => void—A press on the "+": iOS's glass circle before the field, Android's add inside the field's start
addMenuReactNode—Menu items the "+" opens instead of calling onAdd. Opened over the keyboard, the menu stays at the "+" as the keyboard goes and the composer comes down
addMenuOpenboolean—The "+"'s menu open, held by the app (controlled); without it the menu opens and closes on its own
onAddMenuOpenChange(open: boolean) => void—Called as the "+"'s menu opens or closes: a press on the "+", an item chosen, a press outside
addLabelstring"Add"The "+"'s name for assistive technologies
addIconReactNode—The add button's icon in place of the plus: a paperclip, as a messenger attaches; at the composer's icon size
onVoice() => void—Records a voice message: a microphone at the end while the field is empty (a glass circle after the field on iOS, gone with text, the send in the field; the end circle in the primary container on Android, send once there is text)
voiceLabelstring"Record Audio"The microphone's name for assistive technologies
sendLabelstring"Send"The send button's name for assistive technologies
endAdornmentReactNode—Controls inside the field's end, before the send button: Composer.Adornment
accessoryReactNode—Content over the field, within the composer: a reply or an edit the message belongs to
maxLinesnumber6The lines the field grows to before its text scrolls
floatingbooleanfalseOver the end of the screen, the transcript running on under it and fading into canvasColor behind it on iOS, rising over the keyboard on iOS; its room is the bottom of useToolbarInset inside a ToolbarInsetProvider
canvasColorstringthe screen's backgroundThe screen's color under a floating composer on iOS, the transcript fading into it behind the composer as the messenger's edge does: the conversation's canvas (messageCanvasColor)
disabledbooleanfalseStops its parts, the controls inside its field too, and dims their words and icons (iOS's tertiary label, Material's on-surface at 38%); its glass, field and canvas stay as they are
autoFocusboolean—Focuses the field when it mounts
onFocus() => void—Called as the field takes the focus: an Emoji Keyboard in the keyboard's place gives way to the keys
inputRefRef<TextInput>—Ref to the field's TextInput
styleStyleProp<ViewStyle>—Style of the composer
testIDstring—Test id of the composer; its parts are testID-add, testID-input, testID-send and testID-voice

Composer.Adornment

PropTypeDefaultDescription
iconReactNode—The icon, at the field's icon size and color unless it sets its own
accessibilityLabelstring—Its name for assistive technologies
onPress() => void—A press on it
disabledbooleanfalseDims it and stops its press
testIDstring—Test id

useComposerMetrics

useComposerMetrics({ keyboard }) returns { side, bottom, gap, height, radius, accessoryGap }, for a part of the app's own that stands with the composer, such as a reply quoted over the field as its accessory:

  • side and bottom: from the screen's sides and its bottom edge to the row, the safe area counted in. On iOS that is 26 from the sides and 28 from the bottom over a home indicator (6 into its inset, 16 at the least). On Android it is 8 from the sides and 8 over the navigation bar. With the keyboard up (keyboard: true) both are 8, the bottom from the keyboard's top.
  • gap: between the row's circles and the field: 6 on iOS, 8 on Android.
  • height and radius: the field on one line. On iOS it is 40 tall with corners of 20. On Android it is 56 with corners of 28. A reply of the app's own over the field takes the field's radius.
  • accessoryGap: from the accessory to the field, 8 on both.

Tokens

--message-gutter (the sender's side), --message-radius, --message-join-radius, --message-padding-inline, --message-font-size, --message-line-height, --message-gap, --message-group-gap, on iOS --message-gutter-far (the other side), --message-first-baseline, --message-last-baseline-foot and --message-min-width (32, the messenger's least bubble), --message-media-inset (1, a photo's rim), --message-media-blur (10px, the blur under the marks over a picture), the name's --message-author-font-size, --message-author-line-height, --message-author-baseline and --message-author-text-baseline and its colors --message-author-red, --message-author-orange, --message-author-violet, --message-author-green, --message-author-cyan, --message-author-blue and --message-author-pink, the pills' --message-pill-background, --message-pill-color, --message-service-background and --message-service-line-height, the unread band's --message-unread-background, --message-unread-color and --message-unread-border (the band's lines above and below, a pixel each, none by default; the messenger's black at 20% over a wallpaper), the reactions' --message-reaction-selected-background and --message-reaction-selected-color (the reader's capsule and its count, the accent and the bubble's color by default) and --message-reaction-background and --message-reaction-color (others', the accent at 10% and the accent), except in an outgoing bubble, whose reactions take the bubble's own accent, --message-outgoing-accent-color, the picture's --message-avatar-size, --message-avatar-edge and --message-avatar-inset (both platforms), on Android --message-max-width (a percent of the row) and --message-padding-block, --message-outgoing-tint (on iOS by day the color the reader's bubble, its time, checks and quote are made from; the messenger's green by default), --message-outgoing-background, --message-outgoing-color, --message-incoming-background and --message-incoming-color set the bubble on both platforms, --message-outgoing-secondary-color (the time), --message-outgoing-check-color (the checks) and --message-outgoing-check-read-color (the read checks, a messenger's blue if the app wants it; the checks' color by default) an outgoing one's (its words' color at 65% and opaque in a bubble a brand sets); each defaults to the platform's measure.