MessageInputContext

MessageInputContext is provided by Channel. If you are not familiar with the React Context API, see the React docs.

Best Practices

  • Prefer useMessageInputContext for consistent access and typings.
  • Use context handlers (sendMessage, editMessage) to keep behavior aligned with the SDK.
  • Keep input-related props stable to avoid re-renders while typing.
  • Use openAttachmentPicker and closeAttachmentPicker helpers to keep picker state consistent.
  • Respect cooldowns and permissions before allowing sends or uploads.

Basic Usage

Consume MessageInputContext in any child of Channel:

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

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

Alternatively, use the useMessageInputContext hook.

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

const { sendMessage, openAttachmentPicker } = useMessageInputContext();

Values

ValueDescriptionType
additionalTextInputPropsExtra props passed to the underlying TextInput in MessageComposer.object
allowSendBeforeAttachmentsUploadWhen enabled, messages can be sent before all attachments have finished uploading.boolean
asyncMessagesLockDistancePixels the user must drag upward to lock recording and lift their finger without stopping it. Defaults to 50.number
asyncMessagesMinimumPressDurationMinimum press duration (ms) on the record button to start voice recording. Defaults to 500.number
asyncMessagesSlideToCancelDistancePixels the user must drag toward the leading side to cancel voice recording. Defaults to 100.number
attachmentPickerBottomSheetHeightHeight of the attachment picker bottom sheet when open. Defaults to 40% of Window Height.number
audioRecorderManagerInstance of AudioRecorderManager used to manage audio recording state internally.AudioRecorderManager
audioRecordingEnabledEnable or disable audio recording. Defaults to false.boolean
audioRecordingSendOnCompleteControls what happens after a completed voice recording upload. When true, sends the voice recording immediately after upload. When false, keeps it in the composer so the user can add text, attachments, or more recordings before sending. Defaults to true.boolean
closeAttachmentPickerDismiss the attachment picker, if its already open.function
closePollCreationDialogFunction called whenever the close button is pressed on the poll creation modal. Has no effect if PollCreateContent is custom.function
compressImageQualityImage compression quality before upload. On iOS, values >= 0.8 usually keep quality while reducing size. A value of 0.8 can roughly halve file size vs 1.0. Defaults to 0.8 on iOS, 1 on Android.number (0 to 1, 1 is best quality)
createPollOptionGapVertical gap between poll options in the poll creation dialog.number
deleteVoiceRecordingDeletes the current voice recording.() => Promise<void>
doFileUploadRequestCustom function to handle file upload requests.function
editMessageHandles the edit message event on the message input by taking the new message as input and updating the message for the client. See Examples for parameter details.function
handleAttachButtonPressCustomize behavior when the AttachButton is pressed in the message input.() => void
hasCameraPickerEnable the camera picker in MessageComposer. Defaults to true.boolean
hasCommandsEnable commands in MessageComposer. Defaults to true.boolean
hasFilePickerEnable the file picker in MessageComposer. Defaults to true.boolean
hasImagePickerEnable the image picker in MessageComposer. Defaults to true.boolean
inputBoxRefRef for TextInput component within MessageComposer.React ref
messageInputFloatingWhether the message input is floating or not. Defaults to false.boolean
messageInputHeightStoreStore instance for tracking the message input height.MessageInputHeightStore
openAttachmentPickerOpens the attachment picker bottom sheet, if its not open.function
openPollCreationDialogCalled when the poll creation button is clicked in the attachment picker. Use it to override the default modal UI. If overridden, a payload is passed with sendMessage from MessageInputContext for use in CreatePoll. See Examples for parameter details.function
pickAndUploadImageFromNativePickerOpens the native image picker and uploads the selected image.() => Promise<void>
pickFileOpens the native document/file picker and uploads the selected files.() => Promise<void>
sendMessageSends a composed message within MessageComposer component to channel. Attached to the onPress handler of SendButton. The message optimistically gets added to the message list UI first, before actually making the API call to the server. See Examples for parameter details.function
setInputBoxRefSetter function for inputBoxRef.(ref) => void
showPollCreationDialogA boolean signifying whether the poll creation dialog is shown or not. Will always be false if PollCreateContent is custom.boolean
startVoiceRecordingStarts a new voice recording session.() => Promise<boolean | undefined>
stopVoiceRecordingStops the current voice recording.() => Promise<void>
takeAndUploadImageFunction to click an image using the device camera and upload it.() => Promise<void>
threadCan be a LocalMessage or ThreadType. Setting it indicates a thread is open. With Thread, this displays the thread. With the standard MessageList, it keeps singleton components in OverlayProvider in sync. Set thread on all Channel components when a thread is open.object
uploadNewFileFunction to upload an attached file in MessageComposer. Invokes the Message composer Attachment Manager's uploadFiles method to handle the file upload process. Handles the abort controller to make sure the upload can be cancelled if needed.(file: File) => Promise
uploadVoiceRecordingUploads the current voice recording. When sendOnComplete is true, the recording is sent immediately after upload. When false, the recording stays in the composer so the user can add text, attachments, or more recordings before sending.(sendOnComplete: boolean) => Promise<void>

Examples

editMessage

The editMessage 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

openPollCreationDialog

When overridden, the openPollCreationDialog function receives a payload parameter:

ParameterDescription
payload{ sendMessage }

sendMessage

The sendMessage 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