import { StreamChat } from "stream-chat";
import {
Chat,
Channel,
MessageList,
MessageInput,
OverlayProvider,
} from "stream-chat-react-native";
const client = StreamChat.getInstance("api_key");
export const App = () => (
<OverlayProvider>
<Chat client={client}>
<Channel channel={channel}>
<MessageList />
<MessageInput />
</Channel>
</Chat>
</OverlayProvider>
);
MessageInput
MessageInput
component provides all the UI and necessary functionality (e.g, attachment picker, commands, mentions autocomplete etc.) for composing a message.
This component must be used as child of Channel
component.
General Usage
TypeScript
File
type
The File
type is now exported from the stream-chat-react-native
package and extends the FileReference
type from the stream-chat
package. It looks like this:
import { FileReference } from "stream-chat";
export type File = FileReference;
Props
All the configuration for MessageInput
can be done on Channel
component.
Additionally please take a look at our Guide Section on how to customize MessageInput UI
attachmentPickerBottomSheetHeight
Height of the image picker bottom sheet when opened.
Type | Default |
---|---|
Number | 40% of Window Height |
attachmentSelectionBarHeight
Height of the attachment selection bar displayed on the attachment picker.
Type | Default |
---|---|
Number | 52 |
bottomInset
additionalTextInputProps
Additional props provided to the underlying TextInput within MessageInput
.
Type |
---|
object |
asyncMessagesLockDistance
Controls how many pixels to the top side the user has to scroll in order to lock the recording view and allow the user to lift their finger from the screen without stopping the recording.
Type | Default |
---|---|
Number | 50 |
asyncMessagesMinimumPressDuration
Controls the minimum duration(in milliseconds) that the user has to press on the record button in the composer, in order to start recording a new voice message.
Type | Default |
---|---|
Number | 500 |
AsyncMessagesMultiSendEnabled
When it’s enabled, recorded messages won’t be sent immediately. Instead they will “stack up” in the composer allowing the user to send multiple voice recording as part of the same message.
Type | Default |
---|---|
Boolean | true |
asyncMessagesSlideToCancelDistance
Controls how many pixels to the leading side the user has to scroll in order to cancel the recording of a voice message.
Type | Default |
---|---|
Number | 100 |
audioRecordingEnabled
Controls whether the feature is enabled.
Type | Default |
---|---|
Boolean | false |
channel
Channel instance from the StreamChat client.
Type |
---|
Channel |
closeAttachmentPicker
Dismiss the attachment picker, if its already open.
Type |
---|
Function |
closePollCreationDialog
Function called whenever the close button is pressed on the poll creation modal. Has no effect if PollCreateContent
is custom.
Type |
---|
function |
cooldownEndsAt
The time at which the active cool-down will end.
Type |
---|
Date |
editing
inputBoxRef
Ref for TextInput
component within MessageInput
Type |
---|
React ref |
isOnline
The value is true, when current user is connected to chat.
Type |
---|
boolean |
members
Members of current channel. This value is received from backend when you query a channel, either using client.queryChannels()
or channel.watch()
API call.
client.queryChannels()
or channel.watch()
returns only up to 100 members of channel. So if you expect total number of members to be > 100, its better to use client.queryMembers()
API endpoint separately to get the list of members.
Record<
string, // userId
{
banned?: boolean;
created_at?: string;
invite_accepted_at?: string;
invite_rejected_at?: string;
invited?: boolean;
is_moderator?: boolean;
role?: string;
shadow_banned?: boolean;
updated_at?: string;
user?: UserResponse<UserType>;
user_id?: string;
}
>;
Type |
---|
object |
selectedPicker
Value is images
(string), when image attachment picker is open else undefined
.
Type |
---|
’images’ | undefined |
sendMessage
Sends a composed message within MessageInput
component to channel. This function is attached to onPress
handler of SendButton
. The message optimistically gets added to message list UI first, before actually making API call to server.
During this intermediate stage, MessageStatus component will display an indicator for “pending” state.
Type |
---|
Function |
The function takes an object as a parameter with the following properties:
Parameter | Description |
---|---|
localMessage | Contains the message data that will be shown in the UI immediately |
message | Contains the data that will be sent to the backend |
options | Contains options for sending/updating the message |
showPollCreationDialog
A boolean signifying whether the poll creation dialog is shown or not. Will always be false
if PollCreateContent
is custom.
Type |
---|
boolean |
threadList
Tells the Channel component if it is rendering a thread. We use this flag to avoid concurrency problems between a regular channel and a channel containing a thread.
Type |
---|
boolean |
watchers
Watchers of current channel. This value is received from backend when you query a channel, either using client.queryChannels()
or channel.watch()
API call.
client.queryChannels()
or channel.watch()
returns only up to 100 watchers for channel. So if you expect total number of watchers to be > 100, you should request them explicitly using Channel Pagination
Record<
string, // string
UserResponse<UserType>
>;
Type |
---|
object |
UI Component Props
AttachmentUploadPreviewList
Component to render preview of attached files and images, within the MessageInput
component.
Type | Default |
---|---|
ComponentType | AttachmentUploadPreviewList |
AttachmentPickerSelectionBar
Component to render and customize the attachment picker selection bar that displays the image, file and camera icons._createMdxContent
Type | Default |
---|---|
ComponentType | undefined | AttachmentPickerSelectionBar |
AudioRecorder
Custom UI component to render audio recorder controls in MessageInput.
Type | Default |
---|---|
ComponentType | AudioRecorder |
AudioRecordingInProgress
Custom UI component to render audio recording in progress in MessageInput. It renders the waveform, duration etc, for the recording.
Type | Default |
---|---|
ComponentType | AudioRecordingInProgress |
AudioRecordingLockIndicator
Custom UI component to render audio recording lock indicator in MessageInput that can be dragged up to lock the recording start.
Type | Default |
---|---|
ComponentType | AudioRecordingLockIndicator |
AudioRecordingPreview
Custom UI component to render audio recording preview in MessageInput that allows playing the recording.
Type | Default |
---|---|
ComponentType | AudioRecordingPreview |
AudioRecordingWaveform
Custom UI component to render audio recording waveform in MessageInput.
Type | Default |
---|---|
ComponentType | AudioRecordingWaveform |
AutoCompleteSuggestionList
Component to render the autocomplete suggestion list.
Type | Default |
---|---|
ComponentType | AutoCompleteSuggestionList |
CommandInput
Component to render the message input in an active command state.
Type | Default |
---|---|
ComponentType | CommandInput |
CooldownTimer
The cooldown timer is a component that displays a countdown timer for message sending cooldowns in the MessageInput
. It helps to inform users about the remaining time before they can send another message.
Type | Default |
---|---|
ComponentType | CooldownTimer |
CreatePollContent
A custom UI component used to render the entire poll creation form. It has access to the CreatePollContext
values by default through the useCreatePollContext
hook.
Type | Default |
---|---|
ComponentType | CreatePollContent |
Input
Component to render UI part of enclosed MessageInput component. Please read section in guides about Customizing Message Input.
Type |
---|
ComponentType |
InputButtons
Component to render action buttons (CommandsButton and AttachButton) on left side of input box, within enclosed MessageInput
component.
Type | Default |
---|---|
ComponentType | InputButtons |
InputEditingStateHeader
Component to render the header when a message is been edited on the message input.
Type | Default |
---|---|
ComponentType | InputEditingStateHeader |
InputReplyStateHeader
Component to render the header on the message input when a message is been replied to.
Type | Default |
---|---|
ComponentType | InputReplyStateHeader |
Reply
Component to render preview of parent of message for quoted reply.
Type | Default |
---|---|
ComponentType | Reply |
SendButton
Component to render a send message button, within enclosed MessageInput component.
Type | Default |
---|---|
ComponentType | SendButton |
ShowThreadMessageInChannelButton
Component to render a checkbox within enclosed Thread component, which when checked sets a show_in_channel
property to true on a message.
Type | Default |
---|---|
ComponentType | ShowThreadMessageInChannelButton |
StartAudioRecordingButton
Custom UI component for audio recording mic button in MessageInput.
Type | Default |
---|---|
ComponentType | StartAudioRecordingButton |
StopMessageStreamingButton
Custom UI component to display the button to stop AI generation instead of the SendButton
one in MessageInput
.
Type | Default |
---|---|
component | StopMessageStreamingButton |
- General Usage
- TypeScript
- Props
- attachmentPickerBottomSheetHeight
- attachmentSelectionBarHeight
- bottomInset
- additionalTextInputProps
- asyncMessagesLockDistance
- asyncMessagesMinimumPressDuration
- AsyncMessagesMultiSendEnabled
- asyncMessagesSlideToCancelDistance
- audioRecordingEnabled
- channel
- closeAttachmentPicker
- closePollCreationDialog
- cooldownEndsAt
- editing
- inputBoxRef
- isOnline
- members
- selectedPicker
- sendMessage
- showPollCreationDialog
- threadList
- watchers
- UI Component Props
- AttachmentUploadPreviewList
- AttachmentPickerSelectionBar
- AudioRecorder
- AudioRecordingInProgress
- AudioRecordingLockIndicator
- AudioRecordingPreview
- AudioRecordingWaveform
- AutoCompleteSuggestionList
- CommandInput
- CooldownTimer
- CreatePollContent
- Input
- InputButtons
- InputEditingStateHeader
- InputReplyStateHeader
- Reply
- SendButton
- ShowThreadMessageInChannelButton
- StartAudioRecordingButton
- StopMessageStreamingButton