This is documentation for the release candidate Stream Chat React Native SDK v8. For the latest stable version, see the latest version (v7).

MessageInputContext

MessageInputContext is provided by Channel component. If you are not familiar with React Context API, please read about it on React docs.

Basic Usage

MessageInputContext can be consumed by any of the child component of Channel component as following:

import { useContext } from "react";
import { MessageInputContext } from "stream-chat-react-native";

const { sendMessage, toggleAttachmentPicker } = useContext(MessageInputContext);

Alternatively, you can also use useMessageInputContext hook provided by library to consume MessageInputContext.

import { useMessageInputContext } from "stream-chat-react-native";

const { sendMessage, toggleAttachmentPicker } = useMessageInputContext();

Value

additionalTextInputProps

Additional props provided to the underlying TextInput within MessageInput.

Type
object

ayncMessagesLockDistance

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.

TypeDefault
Number50

ayncMessagesMinimumPressDuration

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.

TypeDefault
Number500

ayncMessagesMultiSendEnabled

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.

TypeDefault
Booleantrue

ayncMessagesSlideToCancelDistance

Controls how many pixels to the leading side the user has to scroll in order to cancel the recording of a voice message.

TypeDefault
Number100

audioRecordingEnabled

Controls whether the feature is enabled.

TypeDefault
Booleanfalse

attachmentPickerBottomSheetHandleHeight

Height of the image picker bottom sheet handle.

TypeDefault
Number20

attachmentPickerBottomSheetHeight

Height of the image picker bottom sheet when opened.

TypeDefault
Number40% of Window Height

attachmentSelectionBarHeight

Height of the attachment selection bar displayed on the attachment picker.

TypeDefault
Number52

compressImageQuality

Image compression quality prior to uploading.

On iOS values of 0.8 and above don’t reduce the quality noticeably in most images. A value of 0.8 will reduce the file size in iOS by approximately half compared to a value of 1.

TypeDefault
number 0 to 1
(1 is best quality)
iOS: 0.8
Android: 1

cooldownEndsAt

The time at which the active cool-down will end.

Type
Date

editMessage

Handles the edit message event on the message input by taking the new message as input and updating the message for the client.

Type
Function

The function takes an object as a parameter with the following properties:

ParameterDescription
localMessageContains the message data that will be shown in the UI immediately
optionsContains options for sending/updating the message

handleAttachButtonPress

Function to customize the behaviour when the AttachButton is pressed in the message input.

Type
() => void

hasCameraPicker

Enable the camera picker on the MessageInput component.

TypeDefault
Booleantrue

hasCommands

Enable commands on the MessageInput component.

TypeDefault
booleantrue

hasFilePicker

Enable the file picker on the MessageInput component.

TypeDefault
Booleantrue

hasImagePicker

Enable the image picker on the MessageInput component.

TypeDefault
Booleantrue

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:

ParameterDescription
localMessageContains the message data that will be shown in the UI immediately
messageContains the data that will be sent to the backend
optionsContains options for sending/updating the message

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

doFileUploadRequest

inputBoxRef

Ref for TextInput component within MessageInput

openAttachmentPicker

Opens the attachment picker bottom sheet, if its not open.

Type
Function

openPollCreationDialog

Function called immediately when the poll creation button is clicked in the attachment picker. Can be used to override the default behaviour of the poll creation UI appearing as a Modal.

If overridden, a payload is passed containing the sendMessage callback from MessageInputContext is passed, so that CreatePoll

Type
function
ParameterDescription
payload{ sendMessage }

pickAndUploadImageFromNativePicker

Opens the native image picker and uploads the selected image.

Type
() => Promise<void>

pickFile

Opens the native document/file picker and uploads the selected files.

Type
() => Promise<void>

selectedPicker

Value is images (string), when image attachment picker is open else undefined.

Type
’images’ | undefined

setInputBoxRef

Setter function for inputBoxRef

Type
(ref) => void

showPollCreationDialog

A boolean signifying whether the poll creation dialog is shown or not. Will always be false if PollCreateContent is custom.

Type
boolean

takeAndUploadImage

Function to click an image using the device camera and upload it.

Type
() => Promise<void>

thread

Can be either a LocalMessage object or a ThreadType that when set indicates a thread is open. Both of the types may be used interchangeably.

When used with the Thread component this will display the thread. When used with the standard MessageList component this will prevent any singleton components in the OverlayProvider form getting out of sync.

thread should be set on all Channel components when a thread is open.

Type
object

toggleAttachmentPicker

Function to toggle attachment picker. By default, this function is attached to onPress handler for AttachButton.

Type
Function

uploadNewFile

Function to upload an attached file in MessageInput. This invokes the Message composer Attachment Manager’s uploadFiles method to handle the file upload process.

This handles the abort controller to make sure that the upload can be cancelled if needed.

Type
(file: File) => Promise

Components Props

AttachButton

Component to render the attach button next to input box.

TypeDefault
ComponentTypeAttachButton

AttachmentUploadPreviewList

Component to render preview of attached files and images, within the MessageInput component.

TypeDefault
ComponentTypeAttachmentUploadPreviewList

AudioAttachmentUploadPreview

Component prop used to customize the audio attachment upload preview when its uploading/uploaded in the MessageInput.

TypeDefault
ComponentTypeAudioAttachmentUploadPreview

AudioRecorder

Custom UI component to render audio recorder controls in MessageInput.

TypeDefault
ComponentTypeAudioRecorder

AudioRecordingInProgress

Custom UI component to render audio recording in progress in MessageInput. It renders the waveform, duration etc, for the recording.

TypeDefault
ComponentTypeAudioRecordingInProgress

AudioRecordingLockIndicator

Custom UI component to render audio recording lock indicator in MessageInput that can be dragged up to lock the recording start.

TypeDefault
ComponentTypeAudioRecordingLockIndicator

AudioRecordingPreview

Custom UI component to render audio recording preview in MessageInput that allows playing the recording.

TypeDefault
ComponentTypeAudioRecordingPreview

AudioRecordingWaveform

Custom UI component to render audio recording waveform in MessageInput.

TypeDefault
ComponentTypeAudioRecordingWaveform

AutoCompleteSuggestionHeader

Component to render the autocomplete suggestion header.

TypeDefault
ComponentTypeAutoCompleteSuggestionHeader

AutoCompleteSuggestionItem

Component to render the autocomplete suggestion item.

TypeDefault
ComponentTypeAutoCompleteSuggestionItem

AutoCompleteSuggestionList

Component to render the autocomplete suggestion list.

TypeDefault
ComponentTypeAutoCompleteSuggestionList

AttachmentPickerBottomSheetHandle

Bottom sheet handle component for image picker.

TypeDefault
ComponentTypeundefined | AttachmentPickerBottomSheetHandle

AttachmentPickerSelectionBar

Component to render and customize the attachment picker selection bar that displays the image, file and camera icons._createMdxContent

TypeDefault
ComponentTypeundefined | AttachmentPickerSelectionBar

CameraSelectorIcon

Camera selector component displayed in the attachment selector bar.

TypeDefault
ComponentTypeundefined | CameraSelectorIcon

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.

TypeDefault
ComponentTypeCooldownTimer

CommandsButton

Component to render button next to input box, which when pressed opens commands list.

TypeDefault
ComponentTypeCommandsButton

CommandInput

Component to render the message input in an active command state.

TypeDefault
ComponentTypeCommandInput

CreatePollIcon

The create poll icon component displayed in the attachment selector bar.

TypeDefault
ComponentTypeundefined | CreatePollIcon

FileSelectorIcon

File selector component displayed in the attachment selector bar.

TypeDefault
ComponentTypeundefined | FileSelectorIcon

ImageSelectorIcon

Image selector component displayed in the attachment selector bar.

TypeDefault
ComponentTypeundefined | ImageSelectorIcon

VideoRecorderSelectorIcon

Video recorder selector component displayed in the attachment selector bar.

TypeDefault
ComponentTypeundefined | VideoRecorderSelectorIcon

FileAttachmentUploadPreview

Component prop used to customize the file attachment upload preview when its uploading/uploaded in the MessageInput.

TypeDefault
ComponentTypeFileAttachmentUploadPreview

ImageAttachmentUploadPreview

Component prop used to customize the image attachment upload preview when its uploading/uploaded in the MessageInput.

TypeDefault
ComponentTypeImageAttachmentUploadPreview

VideoAttachmentUploadPreview

Component prop used to customize the video attachment upload preview when its uploading/uploaded in the MessageInput.

TypeDefault
ComponentTypeVideoAttachmentUploadPreview

AttachmentUploadProgressIndicator

Component to render progress indicator on the image/files being uploaded in the message input.

TypeDefault
ComponentTypeAttachmentUploadProgressIndicator

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.

TypeDefault
ComponentTypeInputButtons

InputEditingStateHeader

Component to render the header when a message is been edited on the message input.

TypeDefault
ComponentTypeInputEditingStateHeader

InputReplyStateHeader

Component to render the header on the message input when a message is been replied to.

TypeDefault
ComponentTypeInputReplyStateHeader

MoreOptionsButton

Component to render a button within enclosed MessageInput, which when pressed shows more options such as AttachButton, CommandsButton.

TypeDefault
ComponentTypeMoreOptionsButton

SendButton

Component to render a send message button, within enclosed MessageInput component.

TypeDefault
ComponentTypeSendButton

SendMessageDisallowedIndicator

Component to render indicator stating send message feature is not allowed for current user.

TypeDefault
ComponentTypeSendMessageDisallowedIndicator

ShowThreadMessageInChannelButton

Component to render a checkbox within enclosed Thread component, which when checked sets a show_in_channel property to true on a message.

TypeDefault
ComponentTypeShowThreadMessageInChannelButton

StartAudioRecordingButton

Custom UI component for audio recording mic button in MessageInput.

TypeDefault
ComponentTypeStartAudioRecordingButton

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.

TypeDefault
ComponentTypeCreatePollContent

© Getstream.io, Inc. All Rights Reserved.