import { useContext } from "react";
import { MessageInputContext } from "stream-chat-react-native";
const { sendMessage, toggleAttachmentPicker } = useContext(MessageInputContext);
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:
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.
Type | Default |
---|---|
Number | 50 |
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.
Type | Default |
---|---|
Number | 500 |
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.
Type | Default |
---|---|
Boolean | true |
ayncMessagesSlideToCancelDistance
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 |
attachmentPickerBottomSheetHandleHeight
Height of the image picker bottom sheet handle.
Type | Default |
---|---|
Number | 20 |
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 |
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.
Type | Default |
---|---|
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:
Parameter | Description |
---|---|
localMessage | Contains the message data that will be shown in the UI immediately |
options | Contains 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.
Type | Default |
---|---|
Boolean | true |
hasCommands
Enable commands on the MessageInput
component.
Type | Default |
---|---|
boolean | true |
hasFilePicker
Enable the file picker on the MessageInput
component.
Type | Default |
---|---|
Boolean | true |
hasImagePicker
Enable the image picker on the MessageInput
component.
Type | Default |
---|---|
Boolean | true |
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 |
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
Type |
---|
React ref |
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 |
Parameter | Description |
---|---|
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.
Type | Default |
---|---|
ComponentType | AttachButton |
AttachmentUploadPreviewList
Component to render preview of attached files and images, within the MessageInput
component.
Type | Default |
---|---|
ComponentType | AttachmentUploadPreviewList |
AudioAttachmentUploadPreview
Component prop used to customize the audio attachment upload preview when its uploading/uploaded in the MessageInput
.
Type | Default |
---|---|
ComponentType | AudioAttachmentUploadPreview |
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 |
AutoCompleteSuggestionHeader
Component to render the autocomplete suggestion header.
Type | Default |
---|---|
ComponentType | AutoCompleteSuggestionHeader |
AutoCompleteSuggestionItem
Component to render the autocomplete suggestion item.
Type | Default |
---|---|
ComponentType | AutoCompleteSuggestionItem |
AutoCompleteSuggestionList
Component to render the autocomplete suggestion list.
Type | Default |
---|---|
ComponentType | AutoCompleteSuggestionList |
AttachmentPickerBottomSheetHandle
Bottom sheet handle component for image picker.
Type | Default |
---|---|
ComponentType | undefined | AttachmentPickerBottomSheetHandle |
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 |
CameraSelectorIcon
Camera selector component displayed in the attachment selector bar.
Type | Default |
---|---|
ComponentType | undefined | 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.
Type | Default |
---|---|
ComponentType | CooldownTimer |
CommandsButton
Component to render button next to input box, which when pressed opens commands list.
Type | Default |
---|---|
ComponentType | CommandsButton |
CommandInput
Component to render the message input in an active command state.
Type | Default |
---|---|
ComponentType | CommandInput |
CreatePollIcon
The create poll icon component displayed in the attachment selector bar.
Type | Default |
---|---|
ComponentType | undefined | CreatePollIcon |
FileSelectorIcon
File selector component displayed in the attachment selector bar.
Type | Default |
---|---|
ComponentType | undefined | FileSelectorIcon |
ImageSelectorIcon
Image selector component displayed in the attachment selector bar.
Type | Default |
---|---|
ComponentType | undefined | ImageSelectorIcon |
VideoRecorderSelectorIcon
Video recorder selector component displayed in the attachment selector bar.
Type | Default |
---|---|
ComponentType | undefined | VideoRecorderSelectorIcon |
FileAttachmentUploadPreview
Component prop used to customize the file attachment upload preview when its uploading/uploaded in the MessageInput
.
Type | Default |
---|---|
ComponentType | FileAttachmentUploadPreview |
ImageAttachmentUploadPreview
Component prop used to customize the image attachment upload preview when its uploading/uploaded in the MessageInput
.
Type | Default |
---|---|
ComponentType | ImageAttachmentUploadPreview |
VideoAttachmentUploadPreview
Component prop used to customize the video attachment upload preview when its uploading/uploaded in the MessageInput
.
Type | Default |
---|---|
ComponentType | VideoAttachmentUploadPreview |
AttachmentUploadProgressIndicator
Component to render progress indicator on the image/files being uploaded in the message input.
Type | Default |
---|---|
ComponentType | AttachmentUploadProgressIndicator |
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 |
MoreOptionsButton
Component to render a button within enclosed MessageInput, which when pressed shows more options such as AttachButton, CommandsButton.
Type | Default |
---|---|
ComponentType | MoreOptionsButton |
SendButton
Component to render a send message button, within enclosed MessageInput component.
Type | Default |
---|---|
ComponentType | SendButton |
SendMessageDisallowedIndicator
Component to render indicator stating send message feature is not allowed for current user.
Type | Default |
---|---|
ComponentType | SendMessageDisallowedIndicator |
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 |
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 |
- Basic Usage
- Value
- additionalTextInputProps
- ayncMessagesLockDistance
- ayncMessagesMinimumPressDuration
- ayncMessagesMultiSendEnabled
- ayncMessagesSlideToCancelDistance
- audioRecordingEnabled
- attachmentPickerBottomSheetHandleHeight
- attachmentPickerBottomSheetHeight
- attachmentSelectionBarHeight
- compressImageQuality
- cooldownEndsAt
- editMessage
- handleAttachButtonPress
- hasCameraPicker
- hasCommands
- hasFilePicker
- hasImagePicker
- sendMessage
- closeAttachmentPicker
- closePollCreationDialog
- doFileUploadRequest
- inputBoxRef
- openAttachmentPicker
- openPollCreationDialog
- pickAndUploadImageFromNativePicker
- pickFile
- selectedPicker
- setInputBoxRef
- showPollCreationDialog
- takeAndUploadImage
- thread
- toggleAttachmentPicker
- uploadNewFile
- Components Props
- AttachButton
- AttachmentUploadPreviewList
- AudioAttachmentUploadPreview
- AudioRecorder
- AudioRecordingInProgress
- AudioRecordingLockIndicator
- AudioRecordingPreview
- AudioRecordingWaveform
- AutoCompleteSuggestionHeader
- AutoCompleteSuggestionItem
- AutoCompleteSuggestionList
- AttachmentPickerBottomSheetHandle
- AttachmentPickerSelectionBar
- CameraSelectorIcon
- CooldownTimer
- CommandsButton
- CommandInput
- CreatePollIcon
- FileSelectorIcon
- ImageSelectorIcon
- VideoRecorderSelectorIcon
- FileAttachmentUploadPreview
- ImageAttachmentUploadPreview
- VideoAttachmentUploadPreview
- AttachmentUploadProgressIndicator
- Input
- InputButtons
- InputEditingStateHeader
- InputReplyStateHeader
- MoreOptionsButton
- SendButton
- SendMessageDisallowedIndicator
- ShowThreadMessageInChannelButton
- StartAudioRecordingButton
- CreatePollContent